命令行
- 格式:nginx 參數 [動作]
- 幫助:-? -h
- 使用指定的配置文件:-c
- 指定配置指令:-g
- 指定運行目錄:-p
- 發送信號:-s
指令:
stop:停止服務
quit:優雅停止服務
reload:重載配置文件
reopen:重新開始記錄日誌文件 - 測試配置文件是否有語法錯誤:-t -T
- 打印nginx的版本信息、編譯信息等:-v -V
root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ./nginx -s reload
root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ./nginx -?
nginx version: nginx/1.14.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /home/ubuntu/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ./nginx -v
nginx version: nginx/1.14.2
root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ./nginx -t
nginx: the configuration file /home/ubuntu/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /home/ubuntu/nginx/conf/nginx.conf test is successful
#讀取-c參數後指定的nginx.conf配置文件來啓動Nginx
root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ./nginx -c /home/ubuntu/nginx/conf/nginx.conf
#使用-p參數指定Nginx的安裝目錄
root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ./nginx -p /home/ubuntu/nginx
熱部署
root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ps -ef |grep nginx
root 26122 1 0 16:57 ? 00:00:00 nginx: master process ./nginx
nobody 26409 26122 0 16:58 ? 00:00:00 nginx: worker process
root 27449 26146 0 17:03 pts/1 00:00:00 grep --color=auto nginx
#替換nginx二進制文件
root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# cp nginx nginx.old
#平滑部署
root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# kill -USR2 26122
root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ps -ef |grep nginx
root 26122 1 0 16:57 ? 00:00:00 nginx: master process ./nginx
nobody 26409 26122 0 16:58 ? 00:00:00 nginx: worker process
root 28580 26122 0 17:08 ? 00:00:00 nginx: master process ./nginx
nobody 28581 28580 0 17:08 ? 00:00:00 nginx: worker process
root 28607 26146 0 17:08 pts/1 00:00:00 grep --color=auto nginx
#kill老master進程
root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# kill -WINCH 26122
root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ps -ef |grep nginx
root 26122 1 0 16:57 ? 00:00:00 nginx: master process ./nginx
root 28580 26122 0 17:08 ? 00:00:00 nginx: master process ./nginx
nobody 28581 28580 0 17:08 ? 00:00:00 nginx: worker process
root 28750 26146 0 17:09 pts/1 00:00:00 grep --color=auto nginx
切割日誌文件
root@VM-4-4-ubuntu:/home/ubuntu/nginx/logs# ls -l
total 12
-rw-r--r-- 1 ubuntu ubuntu 0 May 8 16:57 access.log
-rw-r--r-- 1 ubuntu ubuntu 1610 May 8 17:08 error.log #1610字節內容
-rw-r--r-- 1 root root 6 May 8 17:08 nginx.pid
-rw-r--r-- 1 root root 6 May 8 16:57 nginx.pid.oldbin
root@VM-4-4-ubuntu:/home/ubuntu/nginx/logs# mv error.log /home/ubuntu/error.log.bak
root@VM-4-4-ubuntu:/home/ubuntu/nginx/logs# ../sbin/nginx -s reopen #重新生成error日誌文件
root@VM-4-4-ubuntu:/home/ubuntu/nginx/logs# ll
total 20
drwxrwxr-x 2 ubuntu ubuntu 4096 May 8 17:15 ./
drwxrwxr-x 11 ubuntu ubuntu 4096 May 8 16:57 ../
-rw-r--r-- 1 nobody ubuntu 0 May 8 16:57 access.log
-rw-r--r-- 1 nobody root 61 May 8 17:15 error.log #空文件
-rw-r--r-- 1 root root 6 May 8 17:08 nginx.pid
-rw-r--r-- 1 root root 6 May 8 16:57 nginx.pid.oldbin
root@VM-4-4-ubuntu:/home/ubuntu/nginx/logs#
具體資料:https://blog.csdn.net/weixin_46389787/article/details/116941097