1. 程式人生 > 其它 >Nginx防止踩雷指南

Nginx防止踩雷指南

技術標籤:java

此博文詳細羅列出在使用 nginx的一些注意點,長期更新!

常用命令:

  • nginx -s stop 關閉nginx程序
  • nginx –t 檢查配置檔案是否有誤
  • nginx -c filename 為 Nginx 指定一個配置檔案
  • nginx -s reload 因改變了Nginx相關配置,需要重新載入配置而過載
  • nginx -V 顯示 nginx 的版本,編譯器版本和配置引數

搭配Bat指令碼也可以使用:

@echo off
rem 如果啟動前已經啟動nginx並記錄下pid檔案,會kill指定程序
nginx.exe -s stop

rem 測試配置檔案語法正確性
nginx.
exe -t -c conf/nginx.conf rem 顯示版本資訊 nginx.exe -v rem 按照指定配置去啟動nginx nginx.exe -c conf/nginx.conf

如果虛擬機器或者本地有兩個nginx?
在這裡插入圖片描述
cd到nginx的sbin目錄下指定nginx的配置檔案

[root@localhost sbin]# ./nginx -c /opt/nginx/conf/nginx.conf

配置檔案做了修改或者專案的部署包有改動?
重新部署Vue專案會生成dist資料夾,將資料夾放到伺服器後,查出當前vue專案埠的程序

[root@localhost sbin]# lsof -
i:port

然後使用 kill 命令幹掉佔用 port 埠的應用,指定配置檔案,重新載入nginx

[root@localhost sbin]# lsof -i:8080
COMMAND  PID   USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
nginx   7672   root    8u  IPv4 52039357      0t0  TCP *:vcom-tunnel (LISTEN)
nginx   7683 nobody    8u  IPv4 52039357      0t0  TCP *:vcom-tunnel (LISTEN)
[root@localhost
sbin]# kill -9 7672 [root@localhost sbin]# kill -9 7683 [root@localhost sbin]# ./nginx -c /opt/nginx/conf/nginx.conf [root@localhost sbin]# ./nginx -s reload

未完結!