nginx 的啓動、停止與重啓

sudo vim nginx.conf

詳解

./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
     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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章