詳解vue通過NGINX部署在子目錄或者二級(jí)目錄實(shí)踐

這篇文章主要介紹了詳解vue通過NGINX部署在子目錄或者二級(jí)目錄實(shí)踐,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

1、修改 router/index.js

添加一行

base: ‘a(chǎn)dmin’,

2、然后修改 config/index.js

增加一行

const assetsPublicPath = ‘/admin/’

然后修改 下面兩處assetsPublicPath 的值為定義的變量

3、部署時(shí),通過NGINX的反向代理

首先,給需要部署的項(xiàng)目定義一個(gè) NGINX 的 server

server { listen 8001; location / { # vue h5 history mode 時(shí)配置 try_files $uri $uri/ /index.html; root /home/html/travel_admin/dist; index index.html index.htm; } }

再到配置域名的主配置server上做反向代理

server { listen 80; server_name?web.zjj7.com; location / { # 這里是根目錄的項(xiàng)目 try_files $uri $uri/ /index.html; root /home/html/travel/dist; index index.html index.htm; }     # 這里是需要部署的二級(jí)目錄應(yīng)用配置 location http://www.iis7.com/a/lm/vpsdq/ ^~/admin/ { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass?http://127.0.0.1:8001/;?} }

這要重啟NGINX以后,部署就完成了

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容