-
-
執行 list ,列出所有機器
-
執行 dssh 機器序號 ,如 dssh 1 ,選擇機器
二、 創建nginx配置文件
-
進入nginx配置目錄: cd usr/local/nginx/conf/vhosts
-
提升權限: sudo su
-
創建配置文件: touch www.my-app.com.conf ,配置文件以
.conf
結尾,( 若有其他默認配置文件,可以修改該文件后綴,讓默認配置文件失效 ) -
編輯配置文件內容: vim www.my-app.com.conf ,內容如下:
server { listen 80; server_name www.my-app.com; #root /usr/share/nginx/html; # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; access_log /data/log/nginx/www.my-app.com.log my-app; location ~ / { root /data/www/my-app/dist; index index.html; if ($request_filename ~ .*\.(htm|html)$) { add_header Cache-Control no-store; } try_files $uri $uri/ /index.html; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
注:
listen:端口號
server_name:域名
access_log:日志文件在服務器的存儲位置(目錄需手動創建,日志文件自動生成)
location.root:代碼在服務器的存儲位置(項目打包后的dist文件夾位置)
-
退出編輯並保存: :wq
三、部署代碼
-
本地項目代碼打包: npm run build
-
進入配置文件中保存代碼的目錄: cd /data/www/
-
三種方式上傳代碼:
-
a. 從遠程倉庫
clone
,若用http
方式,需輸入git倉庫的用戶名密碼;若用ssh
方式,需配置ssh key配置ssh key:
-
在服務器執行 ssh-keygen -t ed25519 -C "email@example.com" ,一直enter,生成ssh key
-
復制生成的公用ssh key, cd /root/.ssh,vim id_ed25519.pub
-
在git倉庫,設置 -> ssh 秘鑰 -> 粘貼 -> 添加秘鑰
-
-
b.
scp
上傳-
壓縮打包后的dist文件夾, tar -zcvf ./dist.tar.gz ./dist
-
在本地執行 scp /my-app/dist.tar.gz root@xx.xx.xx.xx:/data/www/my-app ,將本地壓縮包上傳到服務器對應的文件夾中
/data/www/my-app
-
解壓上傳的文件, tar -zxvf dist.tar.gz
-
刪除壓縮包, rm -rf dist.tar.gz ,( 也可暫時保存,當做備份 )
-
-
c.
rz -be
上傳-
壓縮打包后的dist文件夾, tar -zcvf ./dist.tar.gz ./dist ,
-
在服務器執行 rz -be ,手動上傳壓縮包
-
解壓上傳的文件, tar -zxvf dist.tar.gz
-
刪除壓縮包, rm -rf dist.tar.gz ,( 也可暫時保存,當做備份 )
-
-
四、重啟nginx
-
進入nginx執行文件目錄, cd /usr/local/nginx/sbin
-
若nginx未啟動,啟動nginx, ./nginx
-
若nginx已啟動,重新啟動nginx, ./nginx -s reload