nginx解决跨域和其他一些配置

先上配置


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。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容