nginx配置
nginx默认配置文件
[root@server1 conf]# pwd
/usr/local/nginx/conf
[root@server1 conf]# ls
fastcgi.conf nginx.conf
fastcgi.conf.default nginx.conf.default
fastcgi_params scgi_params
fastcgi_params.default scgi_params.default
koi-utf uwsgi_params
koi-win uwsgi_params.default
mime.types win-utf
mime.types.default
nginx服务控制方式
//服务控制方式,使用nginx命令
-t //检查配置文件语法
-v //输出nginx的版本
-c //指定配置文件的路径
-s //发送服务控制信号,可选值有{stop|quit|reopen|reload}
检查语法 :-t
[root@server1 ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@server1 ~]#
nginx版本:-v
[root@server1 ~]# nginx -v
nginx version: nginx/1.20.1
指定配置文件路径: -c
[root@server1 conf]# pwd
/usr/local/nginx/conf
#把默认配置文件备份到另一个目录
[root@server1 conf]# cp nginx.conf mime.types /opt/test/
[root@server1 conf]# ls /opt/test/
mime.types nginx.conf
#查看默认配置文件有4个worker_processes进程
[root@server1 conf]# head -5 nginx.conf
#user nobody;
worker_processes 4;
#error_log logs/error.log;
[root@server1 conf]# ps -ef | grep nginx
root 255627 1 0 16:06 ? 00:00:00 nginx: master process nginx
nginx 255628 255627 0 16:06 ? 00:00:00 nginx: worker process
nginx 255629 255627 0 16:06 ? 00:00:00 nginx: worker process
nginx 255630 255627 0 16:06 ? 00:00:00 nginx: worker process
nginx 255631 255627 0 16:06 ? 00:00:00 nginx: worker process
root 263190 1511 0 16:08 pts/0 00:00:00 grep --color=auto nginx
[root@server1 ~]# head -5 /opt/test/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
[root@server1 ~]# nginx -s stop;nginx -c /opt/test/nginx.conf
[root@server1 ~]# ps -ef | grep nginx
root 266383 1 0 16:09 ? 00:00:00 nginx: master process nginx -c /opt/test/nginx.conf
nginx 266384 266383 0 16:09 ? 00:00:00 nginx: worker process
root 266766 1511 0 16:09 pts/0 00:00:00 grep --color=auto nginx
发送服务控制信号:-s
停止服务 stop
[root@server1 ~]# nginx -s stop
[root@server1 ~]# ps -ef | grep nginx
root 333600 1511 0 16:27 pts/0 00:00:00 grep --color=auto nginx
[root@server1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
退出服务:quit
[root@server1 ~]# ps -ef | grep nginx
root 341196 1 0 16:30 ? 00:00:00 nginx: master process nginx
nginx 341197 341196 0 16:30 ? 00:00:00 nginx: worker process
nginx 341198 341196 0 16:30 ? 00:00:00 nginx: worker process
nginx 341199 341196 0 16:30 ? 00:00:00 nginx: worker process
nginx 341200 341196 0 16:30 ? 00:00:00 nginx: worker process
root 341923 1511 0 16:30 pts/0 00:00:00 grep --color=auto nginx
[root@server1 ~]# nginx -s quit
[root@server1 ~]# ps -ef | grep nginx
root 346758 1511 0 16:31 pts/0 00:00:00 grep --color=auto nginx
重新加载文件:reload
[root@server1 ~]# ps -ef | grep nginx
root 355450 1 0 16:33 ? 00:00:00 nginx: master process nginx
nginx 355451 355450 0 16:33 ? 00:00:00 nginx: worker process
nginx 355452 355450 0 16:33 ? 00:00:00 nginx: worker process
nginx 355453 355450 0 16:33 ? 00:00:00 nginx: worker process
nginx 355454 355450 0 16:33 ? 00:00:00 nginx: worker process
root 355606 1511 0 16:34 pts/0 00:00:00 grep --color=auto nginx
[root@server1 ~]# vim /usr/local/nginx/conf/nginx.conf
[root@server1 ~]# head -5 /usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 2; #原本有四个worker process进程现在改为两个
#error_log logs/error.log;
[root@server1 ~]# nginx -s reload #重新加载
[root@server1 ~]# ps -ef | grep nginxroot 355450 1 0 16:33 ? 00:00:00 nginx: master process nginx
nginx 358912 355450 0 16:34 ? 00:00:00 nginx: worker process
nginx 358913 355450 0 16:34 ? 00:00:00 nginx: worker process
root 359145 1511 0 16:34 pts/0 00:00:00 grep --color=auto nginx