[root@localhost home]# nginx -h
nginx version: nginx/1.16.1
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: /usr/local/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
#查看版本信息
nginx -v
#查看版本信息和编译参数
nginx -V
#测试nginx配置
nginx -t
#测试配置文件,并返回所有配置信
nginx -T 测试配置文件,并返回所有配置信息
测试后过程:
2019/10/12 23:15:56 [debug] 8382#0: bind() 0.0.0.0:80 #6
2019/10/12 23:15:56 [debug] 8382#0: counter: 00007F5E844F9080, 1
#使用nginx -t和-T时,忽略error以下的报错信息
nginx -q
#设置nginx工作路径
nginx -p /PATH
#指定配置文件
nginx -c file.conf
#设置全局配置
nginx -g ‘’
使用该命令制定全局配置需要配置文件中未进行配置,不能与配置文件冲突
常用‘deamon off/on;’
#发送信号给ngix master
nginx -s 发送信号给ngix master,stop表示立即结束;quit表示关闭当前端口,停止接收新的消息,并处理完当前的连接;reopen表示重新加载日志文件;reload表示重新加载配置文件
nginx -s stop
#在执行stop前查看当前的nginx进程
[root@localhost nginx]# ps -ef | grep nginx
root 8396 1 0 23:26 ? 00:00:00 nginx: master process nginx
nginx 8397 8396 0 23:26 ? 00:00:00 nginx: worker process
root 8399 4432 0 23:26 pts/0 00:00:00 grep --color=auto nginx
#执行nginx -s stop查看debug日志
2019/10/12 23:26:42 [notice] 8396#0: signal 15 (SIGTERM) received from 8400, exiting #master接收到bash发送的信号量SIGTERM
2019/10/12 23:26:42 [debug] 8396#0: wake up, sigio 0
2019/10/12 23:26:42 [debug] 8396#0: child: 0 8397 e:0 t:0 d:0 r:1 j:0
2019/10/12 23:26:42 [debug] 8396#0: termination cycle: 50
2019/10/12 23:26:42 [debug] 8396#0: sigsuspend
2019/10/12 23:26:42 [debug] 8397#0: epoll: fd:7 ev:0001 d:00007FE5F00A2100
2019/10/12 23:26:42 [debug] 8397#0: channel handler
2019/10/12 23:26:42 [debug] 8397#0: channel: 32
2019/10/12 23:26:42 [debug] 8397#0: channel command: 4
2019/10/12 23:26:42 [debug] 8397#0: channel: -2
2019/10/12 23:26:42 [debug] 8397#0: timer delta: 12716
2019/10/12 23:26:42 [notice] 8397#0: exiting
2019/10/12 23:26:42 [debug] 8397#0: flush files
2019/10/12 23:26:42 [debug] 8397#0: run cleanup: 0000000001F363F8
2019/10/12 23:26:42 [debug] 8397#0: run cleanup: 0000000001F32998
2019/10/12 23:26:42 [debug] 8397#0: cleanup resolver
2019/10/12 23:26:42 [debug] 8397#0: free: 0000000001F36D40
2019/10/12 23:26:42 [debug] 8397#0: free: 0000000001F2DD10
2019/10/12 23:26:42 [debug] 8397#0: free: 0000000001F2C890
2019/10/12 23:26:42 [debug] 8397#0: free: 0000000001F2A870
2019/10/12 23:26:42 [debug] 8397#0: free: 0000000001F257A0
2019/10/12 23:26:42 [debug] 8397#0: free: 0000000001F246E0
2019/10/12 23:26:42 [debug] 8397#0: free: 0000000001F23620
2019/10/12 23:26:42 [debug] 8397#0: free: 0000000001F133A0, unused: 0
2019/10/12 23:26:42 [debug] 8397#0: free: 0000000001F1C3D0, unused: 1
2019/10/12 23:26:42 [debug] 8397#0: free: 0000000001F26860, unused: 0
2019/10/12 23:26:42 [debug] 8397#0: free: 0000000001F2ED20, unused: 0
2019/10/12 23:26:42 [debug] 8397#0: free: 0000000001F32D30, unused: 2336
2019/10/12 23:26:42 [notice] 8397#0: exit
2019/10/12 23:26:42 [notice] 8396#0: signal 17 (SIGCHLD) received from 8397 #master发送kill信号量SIGCHLD给子进程给
2019/10/12 23:26:42 [notice] 8396#0: worker process 8397 exited with code 0
2019/10/12 23:26:42 [debug] 8396#0: shmtx forced unlock
2019/10/12 23:26:42 [debug] 8396#0: wake up, sigio 3
2019/10/12 23:26:42 [debug] 8396#0: reap children
2019/10/12 23:26:42 [debug] 8396#0: child: 0 8397 e:1 t:1 d:0 r:1 j:0
2019/10/12 23:26:42 [notice] 8396#0: exit
2019/10/12 23:26:42 [debug] 8396#0: close listening 0.0.0.0:80 #6 #关闭监听端口
2019/10/12 23:26:42 [debug] 8396#0: run cleanup: 0000000001F32998 #释放内存
2019/10/12 23:26:42 [debug] 8396#0: cleanup resolver
2019/10/12 23:26:42 [debug] 8396#0: free: 0000000001F36D40
2019/10/12 23:26:42 [debug] 8396#0: free: 0000000001F2DD10
2019/10/12 23:26:42 [debug] 8396#0: free: 0000000001F2C890
2019/10/12 23:26:42 [debug] 8396#0: free: 0000000001F2A870
2019/10/12 23:26:42 [debug] 8396#0: free: 0000000001F257A0
2019/10/12 23:26:42 [debug] 8396#0: free: 0000000001F246E0
2019/10/12 23:26:42 [debug] 8396#0: free: 0000000001F23620
2019/10/12 23:26:42 [debug] 8396#0: free: 0000000001F133A0, unused: 0
2019/10/12 23:26:42 [debug] 8396#0: free: 0000000001F1C3D0, unused: 1
2019/10/12 23:26:42 [debug] 8396#0: free: 0000000001F26860, unused: 0
2019/10/12 23:26:42 [debug] 8396#0: free: 0000000001F2ED20, unused: 0
2019/10/12 23:26:42 [debug] 8396#0: free: 0000000001F32D30, unused: 2363
nginx -s quit
[root@localhost nginx]# ps -ef | grep nginx
root 8409 1 0 23:35 ? 00:00:00 nginx: master process nginx
nginx 8410 8409 0 23:35 ? 00:00:00 nginx: worker process
root 8412 4432 0 23:35 pts/0 00:00:00 grep --color=auto nginx
2019/10/12 23:37:03 [notice] 8409#0: signal 3 (SIGQUIT) received from 8413, shutting down
2019/10/12 23:37:03 [debug] 8409#0: wake up, sigio 0
2019/10/12 23:37:03 [debug] 8409#0: child: 0 8410 e:0 t:0 d:0 r:1 j:0
2019/10/12 23:37:03 [debug] 8409#0: sigsuspend
2019/10/12 23:37:03 [debug] 8410#0: epoll: fd:7 ev:0001 d:00007F4D536BD100
2019/10/12 23:37:03 [debug] 8410#0: channel handler
2019/10/12 23:37:03 [debug] 8410#0: channel: 32
2019/10/12 23:37:03 [debug] 8410#0: channel command: 3
2019/10/12 23:37:03 [debug] 8410#0: channel: -2
2019/10/12 23:37:03 [debug] 8410#0: timer delta: 107809
2019/10/12 23:37:03 [notice] 8410#0: gracefully shutting down
2019/10/12 23:37:03 [debug] 8410#0: setproctitle: “nginx: worker process is shutting down”
2019/10/12 23:37:03 [debug] 8410#0: epoll del event: fd:6 op:2 ev:00000000
2019/10/12 23:37:03 [debug] 8410#0: close listening 0.0.0.0:80 #6
2019/10/12 23:37:03 [notice] 8410#0: exiting
2019/10/12 23:37:03 [debug] 8410#0: flush files
2019/10/12 23:37:03 [debug] 8410#0: run cleanup: 00000000013783F8
2019/10/12 23:37:03 [debug] 8410#0: run cleanup: 0000000001374998
2019/10/12 23:37:03 [debug] 8410#0: cleanup resolver
2019/10/12 23:37:03 [debug] 8410#0: free: 0000000001378D40
2019/10/12 23:37:03 [debug] 8410#0: free: 000000000136FD10
2019/10/12 23:37:03 [debug] 8410#0: free: 000000000136E890
2019/10/12 23:37:03 [debug] 8410#0: free: 000000000136C870
2019/10/12 23:37:03 [debug] 8410#0: free: 00000000013677A0
2019/10/12 23:37:03 [debug] 8410#0: free: 00000000013666E0
2019/10/12 23:37:03 [debug] 8410#0: free: 0000000001365620
2019/10/12 23:37:03 [debug] 8410#0: free: 00000000013553A0, unused: 0
2019/10/12 23:37:03 [debug] 8410#0: free: 000000000135E3D0, unused: 1
2019/10/12 23:37:03 [debug] 8410#0: free: 0000000001368860, unused: 0
2019/10/12 23:37:03 [debug] 8410#0: free: 0000000001370D20, unused: 0
2019/10/12 23:37:03 [debug] 8410#0: free: 0000000001374D30, unused: 2336
2019/10/12 23:37:03 [notice] 8410#0: exit
2019/10/12 23:37:03 [notice] 8409#0: signal 17 (SIGCHLD) received from 8410
2019/10/12 23:37:03 [notice] 8409#0: worker process 8410 exited with code 0
2019/10/12 23:37:03 [debug] 8409#0: shmtx forced unlock
2019/10/12 23:37:03 [debug] 8409#0: wake up, sigio 0
2019/10/12 23:37:03 [debug] 8409#0: reap children
2019/10/12 23:37:03 [debug] 8409#0: child: 0 8410 e:1 t:1 d:0 r:1 j:0
2019/10/12 23:37:03 [notice] 8409#0: exit
2019/10/12 23:37:03 [debug] 8409#0: run cleanup: 0000000001374998
2019/10/12 23:37:03 [debug] 8409#0: cleanup resolver
2019/10/12 23:37:03 [debug] 8409#0: free: 0000000001378D40
2019/10/12 23:37:03 [debug] 8409#0: free: 000000000136FD10
2019/10/12 23:37:03 [debug] 8409#0: free: 000000000136E890
2019/10/12 23:37:03 [debug] 8409#0: free: 000000000136C870
2019/10/12 23:37:03 [debug] 8409#0: free: 00000000013677A0
2019/10/12 23:37:03 [debug] 8409#0: free: 00000000013666E0
2019/10/12 23:37:03 [debug] 8409#0: free: 0000000001365620
2019/10/12 23:37:03 [debug] 8409#0: free: 00000000013553A0, unused: 0
2019/10/12 23:37:03 [debug] 8409#0: free: 000000000135E3D0, unused: 1
2019/10/12 23:37:03 [debug] 8409#0: free: 0000000001368860, unused: 0
2019/10/12 23:37:03 [debug] 8409#0: free: 0000000001370D20, unused: 0
2019/10/12 23:37:03 [debug] 8409#0: free: 0000000001374D30, unused: 236
nginx -s reopen
#debug信息
2019/10/12 23:13:12 [notice] 8292#0: signal 10 (SIGUSR1) received from 8374, reopening logs
2019/10/12 23:13:12 [debug] 8292#0: wake up, sigio 0
2019/10/12 23:13:12 [notice] 8292#0: reopening logs
2019/10/12 23:13:12 [debug] 8292#0: reopen file “/usr/local/nginx/logs/debug.log”, old:5 new:3
2019/10/12 23:13:12 [debug] 8292#0: reopen file “/usr/local/nginx/logs/access.log”, old:9 new:5
2019/10/12 23:13:12 [debug] 8292#0: child: 0 -1 e:1 t:1 d:0 r:1 j:0
2019/10/12 23:13:12 [debug] 8292#0: child: 1 8370 e:0 t:0 d:0 r:1 j:0
2019/10/12 23:13:12 [debug] 8292#0: sigsuspend
2019/10/12 23:13:12 [debug] 8370#0: epoll: fd:8 ev:0001 d:00007F363A58B100
2019/10/12 23:13:12 [debug] 8370#0: channel handler
2019/10/12 23:13:12 [debug] 8370#0: channel: 32
2019/10/12 23:13:12 [debug] 8370#0: channel command: 5
2019/10/12 23:13:12 [debug] 8370#0: channel: -2
2019/10/12 23:13:12 [debug] 8370#0: timer delta: 36652
2019/10/12 23:13:12 [notice] 8370#0: reopening logs
2019/10/12 23:13:12 [debug] 8370#0: reopen file “/usr/local/nginx/logs/debug.log”, old:5 new:3
2019/10/12 23:13:12 [debug] 8370#0: reopen file “/usr/local/nginx/logs/access.log”, old:9 new:4
2019/10/12 23:13:12 [debug] 8370#0: worker cycle
2019/10/12 23:13:12 [debug] 8370#0: epoll timer: -
nginx -s reload
#debug信息
2019/10/12 23:42:29 [notice] 8419#0: signal 1 (SIGHUP) received from 8421, reconfiguring
2019/10/12 23:42:29 [debug] 8419#0: wake up, sigio 0
2019/10/12 23:42:29 [notice] 8419#0: reconfiguring
2019/10/12 23:42:29 [debug] 8419#0: posix_memalign: 0000000000A213B0:16384 @16
2019/10/12 23:42:29 [debug] 8419#0: posix_memalign: 0000000000A42850:16384 @16
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A2A3E0:4096
2019/10/12 23:42:29 [debug] 8419#0: read: 8, 0000000000A2A3E0, 2687, 0
2019/10/12 23:42:29 [debug] 8419#0: posix_memalign: 0000000000A46860:16384 @16
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A2B3F0:4280
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A2C4B0:4280
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A4A870:4280
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A4B930:4280
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A4C9F0:4280
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A4DAB0:4280
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A4EB70:4096
2019/10/12 23:42:29 [debug] 8419#0: posix_memalign: 0000000000A4FB80:16384 @16
2019/10/12 23:42:29 [debug] 8419#0: include mime.types
2019/10/12 23:42:29 [debug] 8419#0: include /usr/local/nginx/conf/mime.types
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A53B90:4096
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A54BA0:5231
2019/10/12 23:42:29 [debug] 8419#0: read: 9, 0000000000A53B90, 4096, 0
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A56020:4096
2019/10/12 23:42:29 [debug] 8419#0: read: 9, 0000000000A53B91, 1135, 4096
2019/10/12 23:42:29 [debug] 8419#0: posix_memalign: 0000000000A57030:16384 @16
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A53B90:2048
2019/10/12 23:42:29 [debug] 8419#0: add cleanup: 0000000000A5AC80
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A1C680:1024
2019/10/12 23:42:29 [debug] 8419#0: posix_memalign: 0000000000A5B040:16384 @16
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A1C680:1024
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A1C680:1024
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A1C680:1024
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A1C680:1024
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A1C680:1024
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A53B90:4096
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A53B90:2048
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A53B90:4096
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A53B90:4096
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A1C680:1024
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A53B90:2048
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A5F050:6912
2019/10/12 23:42:29 [debug] 8419#0: malloc: 0000000000A2D570:160
2019/10/12 23:42:29 [debug] 8419#0: log: 0000000000A216F8 8 “/usr/local/nginx/logs/debug.log”
2019/10/12 23:42:29 [debug] 8419#0: log: 0000000000A21720 9 “/usr/local/nginx/logs/access.log”
2019/10/12 23:42:29 [notice] 8419#0: using the “epoll” event method
2019/10/12 23:42:29 [notice] 8419#0: start worker processes
2019/10/12 23:42:29 [debug] 8419#0: channel 4:5
2019/10/12 23:42:29 [notice] 8419#0: start worker process 8422
2019/10/12 23:42:29 [debug] 8419#0: pass channel s:1 pid:8422 fd:4 to s:0 pid:8420 fd:3
2019/10/12 23:42:29 [debug] 8420#0: epoll: fd:7 ev:0001 d:00007FB000687100
2019/10/12 23:42:29 [debug] 8420#0: channel handler
2019/10/12 23:42:29 [debug] 8420#0: channel: 32
2019/10/12 23:42:29 [debug] 8420#0: channel command: 1
2019/10/12 23:42:29 [debug] 8420#0: get channel s:1 pid:8422 fd:3
2019/10/12 23:42:29 [debug] 8420#0: channel: -2
2019/10/12 23:42:29 [debug] 8420#0: timer delta: 8553
2019/10/12 23:42:29 [debug] 8420#0: worker cycle
2019/10/12 23:42:29 [debug] 8420#0: epoll timer: -1
2019/10/12 23:42:29 [debug] 8422#0: add cleanup: 0000000000A5D940
2019/10/12 23:42:29 [debug] 8422#0: malloc: 0000000000A25940:8
2019/10/12 23:42:29 [debug] 8422#0: notify eventfd: 11
2019/10/12 23:42:29 [debug] 8422#0: testing the EPOLLRDHUP flag: success
2019/10/12 23:42:29 [debug] 8422#0: malloc: 0000000000A1D3A0:6144
2019/10/12 23:42:29 [debug] 8422#0: malloc: 00007FB000687010:245760
2019/10/12 23:42:29 [debug] 8422#0: malloc: 0000000000A60B60:98304
2019/10/12 23:42:29 [debug] 8422#0: malloc: 0000000000A78B70:98304
2019/10/12 23:42:29 [debug] 8422#0: epoll add event: fd:6 op:1 ev:00002001
2019/10/12 23:42:29 [debug] 8422#0: epoll add event: fd:5 op:1 ev:00002001
2019/10/12 23:42:29 [debug] 8422#0: setproctitle: “nginx: worker process”
2019/10/12 23:42:29 [debug] 8422#0: worker cycle
2019/10/12 23:42:29 [debug] 8422#0: epoll timer: -1
2019/10/12 23:42:29 [debug] 8419#0: child: 0 8420 e:0 t:0 d:0 r:1 j:0
2019/10/12 23:42:29 [debug] 8419#0: child: 1 8422 e:0 t:0 d:0 r:1 j:1
2019/10/12 23:42:29 [debug] 8419#0: sigsuspend
2019/10/12 23:42:29 [debug] 8420#0: epoll: fd:7 ev:0001 d:00007FB000687100
2019/10/12 23:42:29 [debug] 8420#0: channel handler
2019/10/12 23:42:29 [debug] 8420#0: channel: 32
2019/10/12 23:42:29 [debug] 8420#0: channel command: 3
2019/10/12 23:42:29 [debug] 8420#0: channel: -2
2019/10/12 23:42:29 [debug] 8420#0: timer delta: 100
2019/10/12 23:42:29 [notice] 8420#0: gracefully shutting down
2019/10/12 23:42:29 [debug] 8420#0: setproctitle: “nginx: worker process is shutting down”
2019/10/12 23:42:29 [debug] 8420#0: epoll del event: fd:6 op:2 ev:00000000
2019/10/12 23:42:29 [debug] 8420#0: close listening 0.0.0.0:80 #6
2019/10/12 23:42:29 [notice] 8420#0: exiting
2019/10/12 23:42:29 [debug] 8420#0: flush files
2019/10/12 23:42:29 [debug] 8420#0: run cleanup: 0000000000A403F8
2019/10/12 23:42:29 [debug] 8420#0: run cleanup: 0000000000A3C998
2019/10/12 23:42:29 [debug] 8420#0: cleanup resolver
2019/10/12 23:42:29 [debug] 8420#0: free: 0000000000A40D40
2019/10/12 23:42:29 [debug] 8420#0: free: 0000000000A37D10
2019/10/12 23:42:29 [debug] 8420#0: free: 0000000000A36890
2019/10/12 23:42:29 [debug] 8420#0: free: 0000000000A34870
2019/10/12 23:42:29 [debug] 8420#0: free: 0000000000A2F7A0
2019/10/12 23:42:29 [debug] 8420#0: free: 0000000000A2E6E0
2019/10/12 23:42:29 [debug] 8420#0: free: 0000000000A2D620
2019/10/12 23:42:29 [debug] 8420#0: free: 0000000000A1D3A0, unused: 0
2019/10/12 23:42:29 [debug] 8420#0: free: 0000000000A263D0, unused: 1
2019/10/12 23:42:29 [debug] 8420#0: free: 0000000000A30860, unused: 0
2019/10/12 23:42:29 [debug] 8420#0: free: 0000000000A38D20, unused: 0
2019/10/12 23:42:29 [debug] 8420#0: free: 0000000000A3CD30, unused: 2336
2019/10/12 23:42:29 [notice] 8420#0: exit
2019/10/12 23:42:29 [notice] 8419#0: signal 17 (SIGCHLD) received from 8420
2019/10/12 23:42:29 [notice] 8419#0: worker process 8420 exited with code 0
2019/10/12 23:42:29 [debug] 8419#0: shmtx forced unlock
2019/10/12 23:42:29 [debug] 8419#0: wake up, sigio 0
2019/10/12 23:42:29 [debug] 8419#0: reap children
2019/10/12 23:42:29 [debug] 8419#0: child: 0 8420 e:1 t:1 d:0 r:1 j:0
2019/10/12 23:42:29 [debug] 8419#0: pass close channel s:0 pid:8420 to:8422
2019/10/12 23:42:29 [debug] 8419#0: child: 1 8422 e:0 t:0 d:0 r:1 j:0
2019/10/12 23:42:29 [debug] 8419#0: sigsuspend
2019/10/12 23:42:29 [notice] 8419#0: signal 29 (SIGIO) received
2019/10/12 23:42:29 [debug] 8419#0: wake up, sigio 0
2019/10/12 23:42:29 [debug] 8419#0: sigsuspend
2019/10/12 23:42:29 [debug] 8422#0: epoll: fd:5 ev:0001 d:00007FB000687100
2019/10/12 23:42:29 [debug] 8422#0: channel handler
2019/10/12 23:42:29 [debug] 8422#0: channel: 32
2019/10/12 23:42:29 [debug] 8422#0: channel command: 2
2019/10/12 23:42:29 [debug] 8422#0: close channel s:0 pid:8420 our:8420 fd:3
2019/10/12 23:42:29 [debug] 8422#0: channel: -2
2019/10/12 23:42:29 [debug] 8422#0: timer delta: 103
2019/10/12 23:42:29 [debug] 8422#0: worker cycle
2019/10/12 23:42:29 [debug] 8422#0: epoll timer: -1