nginx 的啟動、停止與重啟


詳解

./nginx  #打開 nginx
nginx -s reload|reopen|stop|quit  #重新加載配置|重啟|停止|退出 nginx
nginx -t   #測試配置是否有語法錯誤

nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

-?,-h           : 打開幫助信息
-v              : 顯示版本信息並退出
-V              : 顯示版本和配置選項信息,然后退出
-t              : 檢測配置文件是否有語法錯誤,然后退出
-q              : 在檢測配置文件期間屏蔽非錯誤信息
-s signal       : 給一個 nginx 主進程發送信號:stop(停止), quit(退出), reopen(重啟), reload(重新加載配置文件)
-p prefix       : 設置前綴路徑(默認是:/usr/local/nginx/-c filename     : 設置配置文件(默認是:/usr/local/nginx/conf/nginx.conf)
-g directives   : 設置配置文件外的全局指令

 

-s signal      Send a signal to the master process.  The argument signal can be one of: stop, quit, reopen, reload.
                    The following table shows the corresponding system signals:

                    stop    SIGTERM
                    quit    SIGQUIT
                    reopen  SIGUSR1
                    reload  SIGHUP

SIGNALS
     The master process of nginx can handle the following signals:

     SIGINT, SIGTERM  Shut down quickly.
     SIGHUP           Reload configuration, start the new worker process with a new configuration, and gracefully shut
                      down old worker processes.
     SIGQUIT          Shut down gracefully.
     SIGUSR1          Reopen log files.
     SIGUSR2          Upgrade the nginx executable on the fly.
     SIGWINCH         Shut down worker processes gracefully.

 

停止

查看進程號:

$ ps -ef|grep nginx
root      5747     1  0 May23 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
500      12037  7886  0 10:00 pts/1    00:00:00 grep nginx
nobody   25581  5747  0 Sep27 ?        00:01:16 nginx: worker process      
nobody   25582  5747  0 Sep27 ?        00:01:25 nginx: worker process      
nobody   25583  5747  0 Sep27 ?        00:02:59 nginx: worker process      
nobody   25584  5747  0 Sep27 ?        00:02:05 nginx: worker process

殺死進程:

$ kill -9 5747

重啟

1. 驗證nginx配置文件是否正確

進入nginx安裝目錄sbin下,輸入命令:

$ ./nginx -t
…… nginx.conf syntax is ok
…… nginx.conf test is successful

看到如上顯示,說明配置文件正確!

2. 重啟nginx服務

進入nginx安裝目錄sbin下,輸入命令:

# ./nginx -s reload
或者
# kill -HUP 5747

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM