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