意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

nginx如何启动

来源:恒创科技 编辑:恒创科技编辑部
2023-12-13 00:44:59

启动可以使用下面的命令行:

cd usr/local/nginx/sbin
./nginx

相关命令:

一.重启

更改配置重启nginx

kill -HUP 主进程号或进程号文件路径

或者使用

cd /usr/local/nginx/sbin
./nginx -s reload

判断配置文件是否正确 

nginx -t -c /usr/local/nginx/conf/nginx.conf

或者

cd /usr/local/nginx/sbin
./nginx -t

二.关闭

查询nginx主进程号

ps -ef | grep nginx

从容停止 kill -QUIT 主进程号

快速停止 kill -TERM 主进程号

强制停止 kill -9 nginx

若nginx.conf配置了pid文件路径,如果没有,则在logs目录下

kill -信号类型 '/usr/local/nginx/logs/nginx.pid'

三.升级

1.先用新程序替换旧程序文件

2.kill -USR2 旧版程序的主进程号或者进程文件名

此时旧的nginx主进程会把自己的进程文件改名为.oldbin,然后执行新版nginx,此时新旧版本同时运行

3.kill -WINCH 旧版本主进程号

4.不重载配置启动新/旧工作进程

kill -HUP 旧/新版本主进程号

从容关闭旧/新进程,kill -QUIT 旧/新进程号

快速关闭旧/新进程,kill -TERM 旧/新进程号

四.实际应用中经常使用

实际应用中经常是关闭,再启动,nginx的启动命令是:

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

-c制定配置文件的路径,不加-nginx会自动加载默认路径的配置文件。

以上是通用的启动命令,研究了一下nginx帮助后发现,有-s参数可对nginx服务进行管理:

# /usr/local/nginx/sbin/nginx -h
nginx version: nginx/0.7.63
Usage: nginx [-?hvVt] [-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
-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

# /usr/local/nginx/sbin/nginx -s reload


更多Nginx相关技术文章,请访问Nginx教程栏目进行学习!

以上就是nginx如何启动的详细内容,更多请关注恒创科技其它相关文章!

上一篇: nginx是什么写的 下一篇: 如何查看nginx日志