Nginx发布Vuejs项目

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

引用网址:https://www.cnblogs.com/mao2080/p/9340026.html

猜你喜欢

转载自blog.csdn.net/liu22985342/article/details/81582834