前提:
- 后端服务地址为:localhost:8989;
- 前端页面目录为:/Users/xxxx/dev/xxxx;
Nginx配置:
默认的配置文件路径为:/usr/local/etc/nginx/nginx.conf
- 在终端中执行: sudo vim /usr/local/etc/nginx/nginx.conf 打开配置文件;
- 按i键进入insert模式;
- 按如下修改即可实现简单的配置目的:
server {
listen 80;
server_name localhost;
#charset utf-8;
#access_log logs/host.access.log main;
location / {
root /Users/xxxx/dev/xxxx;
index /pages/index.html index.htm;
}
location /api {
proxy_pass http://localhost:8989/;
}
}
特别注意:proxy_pass http://localhost:8989/; 末尾一定要有"/",否则会报404