重识Nginx - 04 Nginx常用命令行
Posted 小小工匠
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了重识Nginx - 04 Nginx常用命令行相关的知识,希望对你有一定的参考价值。
文章目录
nginx命令行
帮助命令
-?,-h : this help
[root@VM-0-7-centos sbin]# ./nginx -h
nginx version: nginx/1.22.0
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix]
[-e filename] [-c filename] [-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: /root/ng/artisan_ng/)
-e filename : set error log file (default: logs/error.log)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
[root@VM-0-7-centos sbin]# ./nginx -?
nginx version: nginx/1.22.0
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix]
[-e filename] [-c filename] [-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: /root/ng/artisan_ng/)
-e filename : set error log file (default: logs/error.log)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
[root@VM-0-7-centos sbin]#
使用指定的配置文件 -c
[root@VM-0-7-centos ~]#
[root@VM-0-7-centos ~]# cd ng/artisan_ng/
[root@VM-0-7-centos artisan_ng]# ll
total 36 当前目录 /root/ng/artisan_ng
drwx------ 2 nobody root 4096 Oct 2 09:56 client_body_temp
drwxr-xr-x 2 root root 4096 Oct 2 09:55 conf
drwx------ 2 nobody root 4096 Oct 2 09:56 fastcgi_temp
drwxr-xr-x 2 root root 4096 Sep 26 00:14 html
drwxr-xr-x 2 root root 4096 Oct 2 09:56 logs
drwx------ 2 nobody root 4096 Oct 2 09:56 proxy_temp
drwxr-xr-x 2 root root 4096 Sep 26 00:14 sbin
drwx------ 2 nobody root 4096 Oct 2 09:56 scgi_temp
drwx------ 2 nobody root 4096 Oct 2 09:56 uwsgi_temp
[root@VM-0-7-centos artisan_ng]#
[root@VM-0-7-centos artisan_ng]# ./sbin/nginx -c ./conf/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
^C (忽略这个错误,已经起来了ng)
[root@VM-0-7-centos artisan_ng]# cd sbin/
[root@VM-0-7-centos sbin]# ./nginx -c /root/ng/artisan_ng/conf/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
^C (忽略这个错误,已经起来了ng)
[root@VM-0-7-centos sbin]#
指定配置指令 -g
-g directives : set global directives out of configuration file
指定运行目录 -p
-p prefix : set prefix path
[root@VM-0-7-centos artisan_ng]# pwd
/root/ng/artisan_ng
[root@VM-0-7-centos artisan_ng]# ./sbin/nginx -p `pwd` -c ./conf/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
(忽略这个错误,已经起来了ng)
发送信号 -s
-s signal : send signal to a master process: stop, quit, reopen, reload
- 立刻停止服务 stop
- 优雅的停止服务 quit
- 重载配置文件 reload
- 重新开始记录日志文件 reopen
[root@VM-0-7-centos sbin]# ./nginx -s stop
[root@VM-0-7-centos sbin]# ps -ef|grep nginx
root 447612 447331 0 12:22 pts/0 00:00:00 grep --color=auto nginx
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]# ./nginx -c /root/ng/artisan_ng/conf/nginx.conf
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]# ./nginx -s reload
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]# ./nginx -s quit
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]# ps -ef|grep nginx
root 447738 447331 0 12:23 pts/0 00:00:00 grep --color=auto nginx
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]# ./nginx -c /root/ng/artisan_ng/conf/nginx.conf
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]# ps -ef|grep nginx
root 447751 1 0 12:23 ? 00:00:00 nginx: master process ./nginx -c /root/ng/artisan_ng/conf/nginx.conf
nobody 447752 447751 0 12:23 ? 00:00:00 nginx: worker process
root 447758 447331 0 12:23 pts/0 00:00:00 grep --color=auto nginx
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos artisan_ng]# cd logs/
[root@VM-0-7-centos logs]# ll
total 16
-rw-r--r-- 1 nobody root 2001 Oct 2 12:23 access.log
-rw-r--r-- 1 nobody root 4658 Oct 2 12:23 error.log
-rw-r--r-- 1 root root 7 Oct 2 12:23 nginx.pid
[root@VM-0-7-centos logs]#
[root@VM-0-7-centos logs]# mv access.log access.log_bak 改名
[root@VM-0-7-centos logs]#
[root@VM-0-7-centos logs]#
[root@VM-0-7-centos logs]# cd ../sbin/
[root@VM-0-7-centos sbin]# ./nginx -s reopen 重新生成access 和 errorlog , 没改名的话,不会新生成。
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]# cd ../logs/
[root@VM-0-7-centos logs]# ll
total 16
-rw-r--r-- 1 nobody root 0 Oct 2 12:24 access.log
-rw-r--r-- 1 nobody root 2001 Oct 2 12:23 access.log_bak
-rw-r--r-- 1 nobody root 4947 Oct 2 12:24 error.log
-rw-r--r-- 1 root root 7 Oct 2 12:23 nginx.pid
[root@VM-0-7-centos logs]#
[root@VM-0-7-centos logs]#
测试配置文件是否有语法错误 -t -T
-t : test configuration and exit
-T : test configuration, dump it and exit
[root@VM-0-7-centos sbin]# ./nginx -t
nginx: the configuration file /root/ng/artisan_ng/conf/nginx.conf syntax is ok
nginx: configuration file /root/ng/artisan_ng/conf/nginx.conf test is successful
[root@VM-0-7-centos sbin]# ./nginx -T
nginx: the configuration file /root/ng/artisan_ng/conf/nginx.conf syntax is ok
nginx: configuration file /root/ng/artisan_ng/conf/nginx.conf test is successful
# configuration file /root/ng/artisan_ng/conf/nginx.conf:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events
worker_connections 1024;
http
.....
.....
......
# configuration file /root/ng/artisan_ng/conf/mime.types:
types
text/html html htm shtml;
.....
.....
.....
video/x-msvideo avi;
[root@VM-0-7-centos sbin]#
打印nginx的版本信息、编译信息等 -v -V
-v : show version and exit
-V : show version and configure options then exit
[root@VM-0-7-centos sbin]# ./nginx -v
nginx version: nginx/1.22.0
[root@VM-0-7-centos sbin]# ./nginx -V
nginx version: nginx/1.22.0
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
configure arguments: --prefix=/root/ng/artisan_ng
[root@VM-0-7-centos sbin]#
以上是关于重识Nginx - 04 Nginx常用命令行的主要内容,如果未能解决你的问题,请参考以下文章