从运行 nginx 进程转储 conf

是否可以从正在运行的 nginx 进程中获取 nginx 正在使用的 conf?

获取 conf 文件路径。有时候 ps aux会显示出来,有时候不会。它可能只是类似于 nginx: master process /usr/sbin/nginx的东西(与 /proc/PID/cmdline相同)

  1. 那么 nginx -V是唯一的解决方案吗?
  2. 这个问题可以直接从 nginx 进程转储 conf 数据结构吗?或者至少转储 conf 文件路径?
98914 次浏览

As of Nginx 1.9.2 you can dump the Nginx config with the -T flag:

-T — same as -t, but additionally dump configuration files to standard output (1.9.2).

Source: http://nginx.org/en/docs/switches.html

This is not the same as dumping for a specific process. If your Nginx is using a different config file, check the output for ps aux and use whatever it gives as the binary, e.g. if it gives something like

nginx: master process /usr/sbin/nginx -c /some/other/config

you need to run

/usr/sbin/nginx -c /some/other/config -T

If you are not on 1.9.2 yet, you can dump the config with gdb: