操作系统版本:Centos 7.9
Nginx版本:1.22.1
1、nginx命令
nginx命令格式
nginx [-?hvVtTq] [-s signal] [-p prefix]
[-e filename] [-c filename] [-g directives]
选项说明
帮助: -? -h
使用指定的配置文件: -c
指定配置指令:-g
指定运行目录:-p
测试配置文件是否有语法错误:-t -T
打印nginx的版本信息、编译信息等:-v -V
发送信号: -s 示例: nginx -s reload
信号说明
立刻停止服务:stop,相当于信号SIGTERM,SIGINT
优雅的停止服务:quit,相当于信号SIGQUIT
平滑重启,重新加载配置文件: reload,相当于信号SIGHUP
重新开始记录日志文件:reopen,相当于信号SIGUSR1,在切割日志时用途较大
平滑升级可执行程序:发送信号SIGUSR2,在升级版本时使用
优雅的停止工作进程:发送信号SIGWINCH,在升级版本时使用
查看nginx帮助
[root@nginx01 ~]# nginx -h
nginx version: nginx/1.22.1
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix]
[-e filename] [-c filename] [-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
#发送信号,reload信号 会生成新的worker,但master不会重新生成
-p prefix : set prefix path (default: /apps/nginx/)
#指定Nginx目录
-e filename : set error log file (default: logs/error.log)
#配置错误日志路径
-c filename : set configuration file (default: conf/nginx.conf)
#配置文件路径
-g directives : set global directives out of configuration file
#设置全局指令,注意和配置文件不要同时配置,否则冲突
2、quit 实现worker进程优雅关闭
- 设置定时器: worker_shutdown_timeout
http://nginx.org/en/docs/ngx_core_module.html#worker_shutdown_timeout
Syntax: worker_shutdown_timeout time;
Default: —
Context: main
This directive appeared in version 1.11.11.
Configures a timeout for a graceful shutdown of worker processes. When the
time expires, nginx will try to close all the connections currently open to
facilitate shutdown
- 关闭监听句柄
- 关闭空闲连接
- 在循环中等待全部连接关闭
- 退出nginx所有进程
3、reload 流程
![图片[1]-Nginx命令和信号-李佳程的个人主页](http://www.lijiach.com/wp-content/uploads/2022/11/image-238.png)
利用 reload 可以实现平滑修改配置并生效
- 向master进程发送HUP信号(reload命令)
- master进程校验配置语法是否正确
- master进程打开新的监听端口
- master进程用新配置启动新的worker子进程
- master进程向老worker子进程发送QUIT信号,老的worker对已建立连接继续处理,处理完才会优雅退出.未关闭的worker旧进程不会处理新来的请求
- 老worker进程关闭监听句柄,处理完当前连接后结束进程
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END