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

您所在的位置:网站首页 Nginx的配置文件目录是 找到nginx服务用的是哪个配置文件

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

2023-07-28 23:32| 来源: 网络整理| 查看: 265

背景

在工作中会碰到一台服务器安装了多个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 ~]#

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



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3