启动Nginx

进入sbin目录。

  1. ./nginx

关闭Nginx

进入sbin目录。

  1. 暴力关闭(不推荐的方式)
    1. ./nginx -s stop

    用户和服务器在进行通信时,如果直接就关闭,所有正在请求服务器的连接都会被关闭。

  1. 更好的关闭方式(推荐的方式)
    1. ./nginx -s quit
    • 如果没有客户端请求服务器,就会直接关闭nginx;
    • 如果有客户端和服务器正在发生通信时,会维持连接,当关闭连接后,确认没有连接正在进行,才会关闭nginx。

    注:quit只针对http请求,如果不是,就不适用。

查看Nginx的版本信息

进入sbin目录。

1.版本信息(简单)

  1. ./nginx -v

image.png

2.具体信息

  1. ./nginx -V

image.png

  • nginx version:nginx的版本信息;
  • built by:编译的环境;
  • configure arguments:配置的环境变量。

获取Nginx的帮助信息

进入sbin目录。

  1. ./nginx -?
  1. ./nginx -h

image.png

帮助信息

  1. -?,-h : this help
  2. -v : show version and exit
  3. -V : show version and configure options then exit
  4. -t : test configuration and exit
  5. -T : test configuration, dump it and exit
  6. -q : suppress non-error messages during configuration testing
  7. -s signal : send signal to a master process: stop, quit, reopen, reload
  8. -p prefix : set prefix path (default: /usr/local/nginx/)
  9. -c filename : set configuration file (default: conf/nginx.conf)
  10. -g directives : set global directives out of configuration file

重新加载Nginx的核心配置文件

  1. ./nginx -s reload

一般会搭配到检查nginx.conf配置文件的指令一起使用。

检测nginx.conf配置文件语法是否正确

进入sbin目录。

  1. ./nginx -t

image.png

重新指定一个nginx.conf文件

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

查看Nginx的进程信息

  1. ps -ef|grep nginx

Nginx常用指令 - 图5