一、業務描述:
最近在做一個電商的專案,里面有平臺端和商家端以及用戶端,那么這么多Vue專案如何部署到服務器呢?
二、部署
(1)首先在本地測驗專案可以啟動并且能正常運行,
(2)在專案中輸入npm run build

此時會生成一個檔案

(3)在服務器上安裝Nginx,并將admin-web上傳到服務器,
我上傳的位置:

(4)修改Nginx檔案,找到nginx.conf

三、如果此時有多個vue專案呢?
多加幾個location即可

四、最后記得保存
:wq
五、重新啟動Nginx
systemctl restart nginx
六:Nginx.conf的內容
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/dist/;
index index.html index.htm;
try_files $uri $uri/ @router;
index index.html;
}
#對應上面的@router,主要原因是路由的路徑資源并不是一個真實的路徑,所以無法找到具體的檔案
location @router {
# #因此需要rewrite到index.html中,然后交給路由再處理請求資源
rewrite ^.*$ /index.html last;
}
location /admin {
alias /usr/local/nginx/admin/dist;
index index.html index.htm;
try_files $uri $uri/ @router;
index index.html;
}
#對應上面的@router,主要原因是路由的路徑資源并不是一個真實的路徑,所以無法找到具體的
location @router {
# #因此需要rewrite到index.html中,然后交給路由再處理請求資源
try_files $uri $uri/ @router;
index index.html;
}
#對應上面的@router,主要原因是路由的路徑資源并不是一個真實的路徑,所以無法找到具體>的檔案
location @router {
# #因此需要rewrite到index.html中,然后交給路由再處理請求資源
rewrite ^.*$ /index.html last;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/189624.html
標籤:其他
上一篇:C++:STL學習之vector容器、deque容器使用 案例-評委打分
下一篇:Vue video player 二次加載的時候 報錯 Cannot read property 'pause' of undefined 有木有遇到的
