Dump nginx config from running process?

Solution 1:

You need a gdb installed to dump memory regions of running process.

# Set pid of nginx master process here
pid=8192

# generate gdb commands from the process's memory mappings using awk
cat /proc/$pid/maps | awk '$6 !~ "^/" {split ($1,addrs,"-"); print "dump memory mem_" addrs[1] " 0x" addrs[1] " 0x" addrs[2] ;}END{print "quit"}' > gdb-commands

# use gdb with the -x option to dump these memory regions to mem_* files
gdb -p $pid -x gdb-commands

# look for some (any) nginx.conf text
grep worker_connections mem_*
grep server_name mem_*

You should get something like "Binary file mem_086cb000 matches". Open this file in editor, search for config (e.g. "worker_connections" directive), copy&paste. Profit!

Update: This method isn't entirely reliable. It's based on assumption that nginx process will read configuration and don't overwrite/reuse this memory area later. Master nginx process gives us best chances for that I guess.

Solution 2:

This will not help on this request, but might help other reaching here for the same reason. Newer nginx versions have the -T option to dump the nginx config read from all nginx config files, not from memory:

nginx -T

This can be useful to confirm that a config file is being read, to compare with other server or search for configs.

Again, this will not dump the config from the running process, only what a new process would load.


Solution 3:

The ngx_conf_t is a type of a structure used for configuration parsing. It only exists during configuration parsing, and obviously you can't access it after configuration parsing is complete.

Tags:

Nginx