1、查询nginx.conf主配置文件

通过查询nginx进程查询nginx主配置文件目录

root@kalika:/www/server/panel/vhost/nginx# ps aux | grep nginx
root      105965  0.0  0.7 166416 12956 ?        Ss   Nov07   0:00 nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf
www       423221  0.0  2.4 197504 42928 ?        S    Nov08   0:00 nginx: worker process

如果是通过进程显示是这样的,则代表nginx的执行文件是/usr/local/nginx/sbin/nginx,想要查看配置文件目录则需要通过nginx -V的命令执行

root@kalika:/www/server/panel/vhost/nginx# ps aux | grep nginx
root      7675  0.0  0.0  68968  4444 ?        Ss    2022   0:00 nginx: master process /usr/local/nginx/sbin/nginx

root@kalika:/www/server/panel/vhost/nginx# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.8.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module --add-module=../naxsi-0.56/naxsi_src/

# --prefix=/usr/local/nginx 参数指定了Nginx的安装目录,因此置文件可能在/usr/local/nginx/conf目录中

或者用nginx -t命令也能查询

root@kalika:/opt/nginx# nginx -t
nginx: the configuration file /www/server/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /www/server/nginx/conf/nginx.conf test is successful

又或者systemctl status nginx也能查

root@kalika:~# systemctl status nginx
● nginx.service - LSB: starts the nginx web server
     Loaded: loaded (/etc/init.d/nginx; generated)
     Active: active (running) since Tue 2023-11-21 11:17:35 CST; 1 week 1 day ago
       Docs: man:systemd-sysv-generator(8)
      Tasks: 4 (limit: 2025)
     Memory: 89.2M
        CPU: 16.219s
     CGroup: /system.slice/nginx.service
             ├─  1306 "nginx: master process /www/server/nginx/sbin/nginx -c /www/server/nginx/conf/nginx.conf"
             ├─119969 "nginx: worker process"
             ├─119970 "nginx: worker process"
             └─119971 "nginx: cache manager process"

2、查询nginx配置文件所在位置

只有被include指令指定的配置文件才会被生效,所以想排查有多少配置文件被启用只要查include指定目录就行

root@kalika:~# grep -r "include" /www/server/nginx/conf/nginx.conf
    include /www/server/panel/vhost/nginx/tcp/*.conf;
        include       mime.types;
                #include luawaf.conf;
                include proxy.conf;
        include enable-php.conf;
include /www/server/panel/vhost/nginx/*.conf;

3、查询include目录下的配置文件是否包含server块

server块用于定义主机配置,从中可以查询是否存在域名解析

root@kalika:~# ls /www/server/panel/vhost/nginx
blog.jiecaoyu.cn.conf
root@kalika:~# grep -r "server" /www/server/panel/vhost/nginx/blog.jiecaoyu.cn.conf
server
    server_name blog.jiecaoyu.cn;
    if ($server_port !~ 443)

4、总结

就是各个目录各个配置文件查一下,最后汇总一下即可