nginx配置

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

nginx的配置文件详解

主配置文件:/usr/local/nginx/conf/nginx.conf

  • 默认启动nginx时,
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值