先上配置
server {
listen 80; #1.你想让你的这个项目跑在哪个端口
server_name 47.105.107.186; #2.当前服务器ip
location / {
root /usr/local/yuyihui/dist/;
index index.html index.htm;
}
location /api/ {
proxy_pass http://47.105.107.186:8889/;
}
}
关于proxy_pass后面的地址加不加/的问题
若访问 http://nginx_server/test/index.html
1、若 location /test/ {
proxy_pass http://192.168.1.1/ #有斜杠
}
则该请求被代理到 http://192.168.1.1/index.html
2、若 location /test/ {
proxy_pass http://192.168.1.1 #没有斜杠
}
则该请求被代理到 http://192.168.1.1/test/index.html
location中的配置try_files
try_files $uri $uri/ /index.html;
如果访问http://47.105.107.186/home/xxxx找不到路径,会先匹配 美元符uri即名字为xxxx的文件,如果还找不到,匹配$uri/找一下有没有为xxxx的路径,如果还找不到,则回到index。