Nginx同server配置下配置多個localhost路由地址


nginx多頁面路由配置,進入 nginx/conf/nginx.conf:

http {
......
server {   listen 80;   server_name localhost;   location / {     root C:\xxxx\xxxx\dist;   try_files $uri $uri/ @router;     index index.html index.htm;   }   # 使用 alias 虛擬路徑代理新頁面路由   location /codesendbox {     alias C:\xxx\xxx\dist\codesendbox; # 新頁面或項目資源放到 root 資源目錄下的相應目錄(不然會找不到資源)     try_files $uri $uri/ /codeSendBoxDist/index.html;     index index.html index.htm;   }   error_page 500 502 503 504 /50x.html; location @router{   rewrite ^.*$ /index.html last; } }
...... }

關於通一個 serve 代理多個location路由地址:

1. vue.config.js文件中,修改根路由路徑(為了解決與主項目路由產生沖突),比如修改為:publicPath: "/codesendbox",項目啟動后地址為:localhost:8080/codesendbox

2. 根據上方的步驟配置 nginx

 

 個人博客站點:www.devloper.com  博客、視頻教程與插件工具

-- 時間是個常數,但也是個變數。勤奮的人無窮多,懶惰的人無窮少。 --


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM