Nginx命令行参数

标签(空格分隔): nginx

1 nginx 常用命令


[root@localhost nginx]# nginx -h
nginx version: nginx/1.10.2
Usage: nginx [-?hvVtTq] [-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
  -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/local/nginx/)
  -c filename   : set configuration file (default: /usr/local/nginx/conf/nginx.conf)
  -g directives : set global directives out of configuration file

Nginx 仅有几个命令行参数,完全通过配置文件来配置

-c </path/to/config> 为 Nginx 指定一个配置文件,来代替缺省的。

-t 不运行,而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。

-v 显示 nginx 的版本。

-V 显示 nginx 的版本,编译器版本和配置参数。

2 启动 nginx

[root@localhost ~]# nginx

3 停止 nginx

[root@localhost ~]# nginx -s stop
# or
[root@localhost ~]# nginx -s quit

4 重载 nginx 配置

[root@localhost ~]# nginx -s reload
# or
[root@localhost ~]# nginx -s quit

5 指定配置文件

[root@localhost ~]# nginx -c /usr/local/nginx/conf/nginx.conf

6 检查配置文件是否正确

[root@localhost ~]# nginx -t

7 帮助信息

[root@localhost ~]# nginx -h
[root@localhost ~]# #or
[root@localhost ~]# nginx -?

8 查看 Nginx 版本

[root@localhost ~]# nginx -v
[root@localhost ~]# # or
[root@localhost ~]# nginx -V

9 使用信号

9.1 获得 pid

[root@localhost ~]# ps aux | grep nginx

# or 

[root@localhost ~]# cat /path/to/nginx.pid

9.2 从容停止 nginx,等所有请求结束后关闭服务

[root@localhost ~]# ps aux | grep nginx
[root@localhost ~]# kill -QUIT  pid

9.3 nginx 快速停止命令,立刻关闭进程

[root@localhost ~]# ps aux | grep nginx
[root@localhost ~]# kill -TERM pid

9.4 nginx 强制停止命令


[root@localhost ~]# kill -9 pid

9.5 平滑重启

请注意,在重载前,要先测试一下配置文件

当 nginx 接收到 HUP 信号,它会尝试先解析配置文件(如果指定配置文件,就使用指定的,> 否则使用默认的),成功的话,就应用新的配置文件(例如:重新打开日志文件或监听的套接 > 字)。之后,nginx 运行新的工作进程并从容关闭旧的工作进程。通知工作进程关闭监听套接> 字但是继续为当前连接的客户提供服务。所有客户端的服务完成后,旧的工作进程被关闭。 > 如果新的配置文件应用失败,nginx 将继续使用旧的配置进行工作。

[root@localhost ~]# nginx -t

[root@localhost ~]# ps aux | grep nginx
[root@localhost ~]# kill -HUP pid
# or
[root@localhost ~]# nginx -s reload

9.6 附录:信号

主进程可以处理以下的信号:
TERM, INT 快速关闭
QUIT 从容关闭
HUP 重载配置,用新的配置开始新的工作进程,从容关闭旧的工作进程
USR1 重新打开日志文件 USR2 平滑升级可执行程序。
WINCH 从容关闭工作进程

[root@localhost ~]# kill -l
 1) SIGHUP   2) SIGINT   3) SIGQUIT  4) SIGILL   5) SIGTRAP
 6) SIGABRT  7) SIGBUS   8) SIGFPE   9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT   17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG  24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF 28) SIGWINCH    29) SIGIO   30) SIGPWR
31) SIGSYS  34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 第一章 Nginx简介 Nginx是什么 没有听过Nginx?那么一定听过它的“同行”Apache吧!Ngi...
    JokerW阅读 32,853评论 24 1,002
  • 编译自:http://nginx.org/en/docs/switches.html nginx 支持以下的命令行...
    C86guli阅读 8,285评论 0 0
  • Nginx服务的信号控制 在Nginx服务的启动停止等方式中,有一种是通过信号机制来实现的。Nginx服务在运行时...
    吃瓜的东阅读 9,090评论 0 9
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,286评论 19 139
  • 早上醒来,冷汗直冒。拿掉眼罩,掀开了裹在身上的被子。铮铮的盯着头顶的 天花板,思绪开始漂浮不定。 从某天某个夜晚,...
    颜叙NG阅读 183评论 0 2