不像许多其余软件系统,Nginx 仅有几个命令行参数,彻底经过配置文件来配置sudo nginx -t
-c </path/to/config> 为 Nginx 指定一个配置文件,来代替缺省的。nginx
-t 不运行,而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。测试
-v 显示 nginx 的版本。ui
-V 显示 nginx 的版本,编译器版本和配置参数。this
nginx -h
命令行
-?,-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/share/nginx/) -c filename : set configuration file (default: /etc/nginx/nginx.conf) -g directives : set global directives out of configuration file
stop
— fast shutdown,不处理请求直接中止quit
— graceful shutdown,处理完请求后中止reload
— reloading the configuration file,重载配置文件reopen
— reopening the log filesTERM, INT | 快速关闭 |
QUIT | 从容关闭 |
HUP | 重载配置 用新的配置开始新的工做进程 从容关闭旧的工做进程 |
USR1 | 从新打开日志文件 |
USR2 | 平滑升级可执行程序。 |
WINCH | 从容关闭工做进程 |
TERM, INT | 快速关闭 |
QUIT | 从容关闭 |
USR1 | 从新打开日志文件 |
启动nginxsudo nginx
或者sudo /usr/local/nginx/nginx
使用ps -ef|grep nginx
查看nginx的pid、
命令格式:kill 信号 nginx进程号
sudo kill -QUIT 25743
优雅的关闭nginx进程,在处理完全部正在使用nginx用户请求后再关闭nginx进程,等同于/usr/local/nginx -s quit
sudo kill -HUP 7370
nginx进程不关闭,可是从新加载配置文件。等同于/usr/local/nginx -s reload
sudo kill -USR1 7370
不用关闭nginx进程就能够重读日志,此命令能够用于nginx的日志定时备份,按月/日等时间间隔分割有用sudo kill -USR2 7370
nginx的版本须要升级的时候,不须要中止nginx,就能对nginx升级sudo kill -WINCH 7370
优雅的关闭nginx旧版本的进程,配合USR2对nginx升级若是嫌麻烦能够不用查看进程号,直接使用命令进行操做
例如日志
kill -QUIT `cat /usr/local/nginx/nginx.pid`
其中/usr/local/nginx/nginx.pid 为nginx.conf中pid命令设置的参数,用来存放nginx主进程号的文件code
用nginx二进制文件绝对路径sudo /usr/local/nginx/nginx
或sudo nginx
启动进程
ps -ef |grep nginx kill -QUIT nginx主进程号
nginx从容中止命令,等全部请求结束后关闭服务编译器
kill -9 nginx主进程号
强行中止it
重启类型
1.简单型,先关闭进程,修改你的配置后,重启进程。
kill -QUIT cat /usr/local/nginx/nginx.pid
sudo /usr/local/nginx/nginx
2.从新加载配置文件,不重启进程,不会中止处理请求HUP
3.平滑更新nginx二进制,不会中止处理请求USR2与WINCH