一句简单命令重启nginx

最近我的多个VPS经常出现502错误,经常需要重启nginx,但网上的很多教程都需要繁琐的启动脚本,远不如apache的重启命令那么简单。
但研究了一下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

于是我执行
# /usr/local/nginx/sbin/nginx -s  reload
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

原创文章,转载请注明: 转载自xuun's blog

本文链接地址: 一句简单命令重启nginx

  1. 牛逼啊!专业啊!

    • linuxguy
    • 2010年11月2日

    非常强大,受用。我之前用张宴教程教的
    平滑重启
    kill -HUP `/usr/local/nginx-64/logs/nginx.pid`
    nnd!没用,新改的配置没生效,忽悠人。
    你这句 reload非常实用,简单,还生效
    谢谢楼主

  2. reopen, reload 有什么区别?

      • test
      • 2011年02月16日

      reopen是kill nginx,然后启动nginx,是真正意义上的nginx重启
      reload是重新加载配置文件.

  3. 哈哈,我也在捣鼓vps,刚好来找这命令

  4. 输了这个命令,怎么没有任何输出信息?也不知道有没有执行成功

    • nginx -s reload && echo OK
      如果输出了OK,就证明了reload正确的完成了!

      • 有些程序执行后没有任何输出,一直不知道怎么才算执行了,看到你的回复恍然大悟。

  1. 没有通告