怎么找Nginx加载的配置文件

Nginx安装完成之后,可以根据Nginx的运行命令获取加载的配置文件。
一般情况下名称是nginx.conf,可能在以下几个文件夹中:

  • /usr/local/nginx/conf
  • /etc/nginx
  • /usr/local/etc/nginx
  • /opt/nginx/conf
    具体加载的配置文件在哪,以下文为准
    执行以下命令,看正在运行的Nginx进程的信息
$ ps -aux | grep nginx
root      2139  0.0  0.0 148084  3152 ?        Ss   09:24   0:00 nginx: master process /opt/nginx/sbin/nginx
或者
root     21113  0.0  0.0  63304   920 ?        Ss   12:49   0:00 nginx: master process nginx
或者
root     23064  0.0  0.0  76156  2816 ?        Ss   12:54   0:00 nginx: master process /opt/nginx/sbin/nginx -c /etc/nginx/nginx.conf

正常情况下会出现多个进程,我们只找nginx: master process,主进程,主进程后边的命令是不固定的。
如果后边是命令的后边有 -c /etc/nginx/nginx.conf,如上图中第三种情况,那么配置文件就是 -c后的文件,这种是指定配置文件启动的。如果没有-c 参数,那么需要使用命令查找加载的默认配置文件。总的来说就是Nginx的启动命令,加 -t ,这个命令是校验配置文件,后边不加其他参数,校验的就是默认配置文件,不管校验成功还是失败,都会把配置文件路径打印出来。
如果启动命令是/opt/nginx/sbin/nginx,那么执行

$ sudo /opt/nginx/sbin/nginx -t
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful

如果启动命令是nginx,那么执行

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值