第一种方式
ps
指令
ps -ef | grep nginx
执行结果:
root 13865 1 0 2021 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
-c
后的目录即为当前运行的配置文件
第二种方式
- 查看
nginx
的PID
netstat -anop | grep 0.0.0.0:80
执行结果:
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6899/nginx: worker off (0.00/0/0)
- 通过
netstat
命令得到进程ID
6899
来查询nginx
路径
ll /proc/6899/exe
执行结果:
lrwxrwxrwx 1 www www 0 1月 14 05:33 /proc/6899/exe -> /usr/local/nginx/sbin/nginx
- 获取到
nginx
的执行路径后,使用-t
参数即可获取该进程对应的配置文件路径
/usr/local/nginx/sbin/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
第三种
在上述方法中得到了进程号后可通过如下命令获得配置文件
ll /proc/6899/exe
执行结果:
lrwxrwxrwx 1 www www 0 1月 14 05:33 /proc/6899/exe -> /usr/local/nginx/sbin/nginx