首页  >  文章  >  运维  >  nginx如何启动

nginx如何启动

步履不停
步履不停原创
2019-06-22 11:46:2418754浏览

nginx如何启动

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

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如何启动的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn