將打包好的前端項目文件放到指定目錄中
一開始我會想要把打包後的項目文件放到 Nginx 默認的目錄,但這樣實際上是不好的,項目文件完全可以放在單獨的目錄中方便統一管理
修改 Nginx 配置,指向上述目錄
一般來說就是修改 Nginx 的默認配置文件 nginx.conf 即可,但不推薦這麼做,既然上面使用了單獨的目錄管理項目文件,那麼這裏也推薦創建單獨的 Nginx 配置文件來管理此項目的 Nginx 配置
在 Nginx 的默認配置文件 nginx.conf 中,最後一行寫着 include /etc/nginx/conf.d/*.conf;
這說明只要是該目錄下文件後綴爲 conf 的文件都會被自動加載到 Nginx 配置中
所以可以前往該目錄,創建此項目的配置文件
1.1 基本配置
server {
listen 9000;
server_name 1.1.1.3;
#access_log logs/access_example.log main;
root /home/work/project/frontopwf/dist;
location / {
try_files $uri $uri/ @router;
}
location @router {
rewrite ^.*$ /index.html last;
}
}
前後端分離nginx配置
server {
listen 9000;
server_name frontopwf.intra.yiducloud.cn;
access_log /home/work/logs/vue_access.log main;
root /home/work/project/frontopwf/dist;
location / {
try_files $uri $uri/ @router;
}
location @router {
rewrite ^.*$ /index.html last;
}
}
server {
listen 8000;
server_name workorder.intra.yiducloud.cn;
access_log /home/work/logs/workorder_access.log main;
location / {
proxy_pass http://127.0.0.1:8001;
}
}
重新啓動 Nginx
nginx -s reload #可以重新加載 Nginx 的配置文件,但如果配置文件有錯,不一定會拋出異常
nginx -s stop #先停止 Nginx 服務,再使用 nginx 嘗試啓動 Nginx 服務,如果配置文件有異常,則會拋出異常告知啓動失敗
更新前端項目包
將更新後的前端項目打包,直接傳到之前的前端文件目錄即可,Nginx 不需要重啓