官方文档地址 : http://nginx.org/en/docs/
命令 | 描述 |
---|---|
-?|-h | 打开帮助 |
-c file | 指定文件作为配置文件 |
-e file | 使用指定的错误日志文件来存储日日志 |
-p prefix | 设置nginx路径前缀,即将保留服务器文件的目录(默认值为/usr/local/nginx)。 |
-q | 在配置测试期间禁止显示非错误消息。 |
-s {signal} | 向 主进程发送信号。参数信号可以是以下之一: stop - 快速关闭 quit - 正常关闭 reopen - 重新打开日志文件 reload - 重新加载配置 |
-t | 检查配置的语法是否正确,同时会把配置路径展示出来 |
-T | 与相同-t,但另外将配置内容打印输出 |
-v | 打印nginx版本 |
-V | 打印nginx版本、编译器版本和配置参数 |
-g | 设置 全局配置指令 |
命令输出
nginx -?
[root@localhost ~]# nginx -?
nginx version: nginx/1.18.0
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: /etc/nginx/)
-c filename : set configuration file (default: /etc/nginx/nginx.conf)
-g directives : set global directives out of configuration file
[root@localhost ~]#
nginx -h
[root@localhost ~]# nginx -h
nginx version: nginx/1.18.0
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: /etc/nginx/)
-c filename : set configuration file (default: /etc/nginx/nginx.conf)
-g directives : set global directives out of configuration file
[root@localhost ~]#
nginx -c
[root@localhost nginx]# ls
conf.d fastcgi_params koi-utf koi-win mime.types modules nginx2.conf nginx.conf scgi_params uwsgi_params win-utf
[root@localhost nginx]# nginx -c ./nginx2.conf
[root@localhost nginx]# ps -ef|grep nginx
root 23953 1 0 18:15 ? 00:00:00 nginx: master process nginx
nginx 23960 23953 0 18:16 ? 00:00:00 nginx: worker process
root 23976 1 0 18:18 ? 00:00:00 nginx: master process nginx -c ./nginx2.conf
nginx 23977 23976 0 18:18 ? 00:00:00 nginx: worker process
root 23998 22625 0 18:21 pts/0 00:00:00 grep --color=auto nginx
又启动两进程,不是我想象的切换配置文件,并且nginx -s stop 还关闭不了原配置文件的进程,只能kill 掉,挠头
启动时指定
[root@localhost conf.d]# ps -ef|grep nginx
root 24260 22625 0 18:49 pts/0 00:00:00 grep --color=auto nginx
[root@localhost conf.d]# nginx -c /etc/nginx/nginx2.conf
[root@localhost conf.d]# ps -ef|grep nginx
root 24273 1 0 18:49 ? 00:00:00 nginx: master process nginx -c /etc/nginx/nginx2.conf
nginx 24274 24273 0 18:49 ? 00:00:00 nginx: worker process
root 24287 22625 0 18:50 pts/0 00:00:00 grep --color=auto nginx
[root@localhost conf.d]#
这时候只有nginx2.conf生效,OK
nginx -c 需要1.19.5往上版本
[root@localhost nginxdata]# nginx -e /data/logs/
nginx: invalid option: "e"
[root@localhost nginxdata]#
nginx -p 设置完之后没有生效,不清楚是版本问题还是其他问题
[root@localhost nginxdata]# nginx -p /data/nginxdata/
[root@localhost nginxdata]# nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
-q 这个命令也没搞懂,非错误日志还是产生了,这个命令到底是屏蔽的哪里的信息呢
[root@localhost nginx]# ps -ef|grep nginx
root 25445 1 0 20:42 ? 00:00:00 nginx: master process nginx -q
nginx 25446 25445 0 20:42 ? 00:00:00 nginx: worker process
root 25456 25172 0 20:43 pts/0 00:00:00 grep --color=auto nginx
[root@localhost nginx]# tail -f access.log
172.16.20.184 - - [11/May/2021:20:43:06 +0800] "GET /static/img/symbol.1ead5b97.png HTTP/1.1" 200 17498 "http://192.168.1.65:8090/unified-display/display-jkstack" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" "-"
这个命令启动后,提示打开 /var/run/nginx.pid 失败,摸不着头脑
[root@localhost nginx]# ps -ef|grep nginx
root 25445 1 0 20:42 ? 00:00:00 nginx: master process nginx -q
nginx 25446 25445 0 20:42 ? 00:00:00 nginx: worker process
root 25473 25172 0 20:46 pts/0 00:00:00 grep --color=auto nginx
[root@localhost nginx]# nginx -s stop
nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)
[root@localhost nginx]# nginx -s quit
nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)
[root@localhost nginx]# ps -ef|grep nginx
root 25445 1 0 20:42 ? 00:00:00 nginx: master process nginx -q
nginx 25446 25445 0 20:42 ? 00:00:00 nginx: worker process
root 25479 25172 0 20:46 pts/0 00:00:00 grep --color=auto nginx
[root@localhost nginx]#
nginx -s stop
[root@localhost nginx]# ps -ef|grep nginx
root 25489 1 0 20:48 ? 00:00:00 nginx: master process nginx
nginx 25490 25489 0 20:48 ? 00:00:00 nginx: worker process
root 25492 25172 0 20:48 pts/0 00:00:00 grep --color=auto nginx
[root@localhost nginx]# nginx -s stop
[root@localhost nginx]# ps -ef|grep nginx
root 25495 25172 0 20:48 pts/0 00:00:00 grep --color=auto nginx
[root@localhost nginx]#
nginx -s quit
[root@localhost nginx]# nginx
[root@localhost nginx]# ps -ef|grep nginx
root 25503 1 0 20:49 ? 00:00:00 nginx: master process nginx
nginx 25504 25503 0 20:49 ? 00:00:00 nginx: worker process
root 25506 25172 0 20:49 pts/0 00:00:00 grep --color=auto nginx
[root@localhost nginx]# nginx -s quit
[root@localhost nginx]# ps -ef|grep nginx
root 25509 25172 0 20:49 pts/0 00:00:00 grep --color=auto nginx
[root@localhost nginx]#
nginx -s reload
[root@localhost nginx]# nginx -s reload
[root@localhost nginx]#
会将配置文件重新加载,这边1.18.0亲测,就不截图了
nginx -s reopen
[root@localhost nginx]# tail -f access.log
172.16.20.184 - - [11/May/2021:20:43:06 +0800] "GET /static/img/symbol.1ead5b97.png HTTP/1.1" 200 17498 "http://192.168.1.65:8090/unified-display/display-jkstack" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" "-"
[root@localhost nginx]# mv access.log access-test.log
[root@localhost nginx]# tail -f access-test.log
172.16.20.184 - - [11/May/2021:20:43:07 +0800] "GET /static/img/bg.e627c758.png HTTP/1.1" 200 1018234 "http://192.168.1.65:8090/static/css/display~unifiedDisplay.7a37f296.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" "-"
[root@localhost nginx]# nginx -s reopen
[root@localhost nginx]# tail -f access-test.log
当我们线上拆分日志的时候,把当前日志文件移走
但是因为在 linux 下的文件句柄,文件在被打开的情况下 mv 移走文件,操作这个文件的进程还是有这个文件的信息,原进程还是读写原来的文件,
简单的 mv 无法生效也就无法完成我们想要的文件分隔。
一般我们需要 2 步。
移走文件并重命名。
mv access.log access-test.log
利用 nginx 的 reopen 功能,完成新日志文件的生成。
nginx -s reopen
nginx -t
[root@localhost nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost nginx]#
nginx -T
[root@localhost nginx]# nginx -T
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# configuration file /etc/nginx/nginx.conf:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
.................
nginx -v
[root@localhost nginx]# nginx -v
nginx version: nginx/1.18.0
nginx -V
nginx version: nginx/1.18.0
[root@localhost nginx]# nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
nginx -g
[root@localhost logs]# nginx -g "error_log /data/logs/nginx.log;"
[root@localhost logs]# nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
......
[root@localhost logs]# tail -f nginx.log
2021/05/11 21:19:53 [emerg] 25816#25816: bind() to 0.0.0.0:80 failed (98: Address already in use)
...
[root@localhost logs]# pwd
/data/logs