找到nginx服务用的是哪个配置文件

背景

在工作中会碰到一台服务器安装了多个nginx的服务的情况。
Nginx的主配置文件有的在/etc/nginx/nginx.conf而有的在/usr/local/nginx/conf/nginx.conf,还有很多情况配置文件在很多自定义的位置。找到主配置文件后,通过查看主配置文件的内容就可以找到子配置文件了。

问题点

当前nginx服务的主配置文件具体是哪个呢?

一.nginx进程用的哪个主配置文件的方法

方法1适合找到没有用默认配置文件的情况发,方法2适合找到默认配置文件的情况

方法1:部分情况通过ps -ef | grep nginx能直接找到

示例如下,master进程中直接列出了nginx的主配置文件。

[root@vm22 ~]# ps -ef | grep  nginx
root      1703     1  0 20:44 ?        00:00:00 nginx: master process nginx -c /etc/nginx/nginx.conf
nginx     1704  1703  0 20:44 ?        00:00:00 nginx: worker process
nginx     1705  1703  0 20:44 ?        00:00:00 nginx: worker process
root      1708  1548  0 20:44 pts/0    00:00:00 grep --color=auto nginx
方法2:nginx -t查看默认的nginx配置文件路径
#步骤1  找到nginx的主进程id,如下pid为1863
[root@vm22 ~]# ps -ef | grep nginx
root      1863     1  0 21:00 ?        00:00:00 nginx: master process /usr/sbin/nginx
nginx     1864  1863  0 21:00 ?        00:00:00 nginx: worker process
nginx     1865  1863  0 21:00 ?        00:00:00 nginx: worker process
root      1868  1548  0 21:00 pts/0    00:00:00 grep --color=auto nginx

#步骤2  找到1863进程启动nginx的绝对路径
如下exe的这一行可看到nginx的绝对路径为/usr/sbin/nginx
[root@vm22 ~]# ll /proc/1863  # 其中1863为步骤1查出来的pid
....忽略部分内容....
lrwxrwxrwx  1 root root 0 4月  30 21:02 exe -> /usr/sbin/nginx
....忽略部分内容....

说明:这次举例其实步骤1已经知道了nginx的绝对路径,步骤2有些情况会用的到。有些时候电脑装了多个nginx,而且步骤1看不到绝对路径时可以用步骤2来找绝对路径。

#步骤3  找到nginx主配置文件,如下命令的输出
[root@vm22 ~]# /usr/sbin/nginx -t  # 其中/usr/sbin/nginx为步骤2查出来的绝对路径
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

二.查看nginx主配置文件都include了哪些子配置文件

grep include 主配置文件,如下实例

[root@vm22 ~]# grep include  /etc/nginx/nginx.conf
include /usr/share/nginx/modules/*.conf;
    include             /etc/nginx/mime.types;
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/default.d/*.conf;
#        include /etc/nginx/default.d/*.conf;  #注意此行前面有注释
[root@vm22 ~]#

找到主配置文件和子配置文件后,就可以愉快的查看和修改配置文件,愉快的板砖啦!

  • 8
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值