Nginx部署vue项目


原文地址:https://www.cnblogs.com/mao2080/p/9340026.html

1、问题描述

给前端同事部署了web项目之后,访问发现除了index.html可以访问,其他的路径使用了“伪静态”。比如访问:http://localhost:8081/user/login,访问即报404错误,这个实际上是请求HTML相关资源而非后台接口,后面网上查了相关资料找到了解决办法。

2、配置文件

复制代码
 1     upstream portalServer {
 2         server 192.168.1.1:8080;
 3     }
 4     
 5     server {
 6         listen       8081;
 7         server_name  localhost;
 8 
 9         root   /usr/local/application/nginx/web/build;
10         
11         location / {
12             try_files $uri $uri/ @router;
13             index  index.html;
14         }
15         
16         location @router{
17             rewrite ^.*$ /index.html last;
18         }
19         #代理后台接口
20         location /api/ {
21             proxy_pass http://portalServer/;
22             proxy_set_header Host $host:$server_port;
23         }
24 
25         error_page   500 502 503 504  /50x.html;
26         location = /50x.html {
27             root   html;
28         }
29     } 
复制代码

3、参考网站

https://my.oschina.net/u/1760791/blog/1575808

http://blog.sina.com.cn/s/blog_bd418dfa0102wser.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM