Nginx服务之核心要点

纸上得来终觉浅,绝知此事要躬行。

Nginx服务之核心要点 Nginx服务之核心要点

1. 命令行选项

  • [1] 命令帮助
$ nginx -h
nginx version: nginx/1.14.0 (Ubuntu)
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/share/nginx/)
  -c filename   : set configuration file (default: /etc/nginx/nginx.conf)
  -g directives : set global directives out of configuration file
  • [2] 命令帮助
Nginx 命令行选项 子选项 选项说明
nginx -c file - 指定配置文件代替默认的配置文件加载;默认/etc/nginx/nginx.conf
nginx -g directives - 设置全局配置指令
nginx -p prefix - 指定安装路径;默认安装在/usr/share/nginx/
nginx -q - 测试中不显示错误信息
nginx -s signal - 给master进程发送信号量
stop 立即停止
quit 优雅停止
reload 重载配置文件
reopen 重新打开日志文件
nginx -t - 测试配置文件的语法规范
nginx -h - 显示帮助信息
  • [3] 演示说明
# 指定配置文件
$ sudo nginx -c /data/ci/nginx.conf -s reload

1. 使用-g参数设置启动全局变量
$ sudo nginx -g "pid /var/run/nginx.pid; worker_processes `sysctl -n hw.ncpu`"
  • [4] 信号量
$ 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

2. 设置哈希表