Skip to content

Instantly share code, notes, and snippets.

@widnyana
Created June 24, 2016 06:01
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save widnyana/e0cb041854b6e0c9e0d823b37994d343 to your computer and use it in GitHub Desktop.
Save widnyana/e0cb041854b6e0c9e0d823b37994d343 to your computer and use it in GitHub Desktop.
Dump Current Nginx Config

you need to install gdb (GNU Debugger)

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.

# 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_*
@bbouille
Copy link

bbouille commented Jan 8, 2018

Thanks for the tips !

@ilyaklushin
Copy link

Thanks. I'm very appreciate this script. It still works with latest nginx /1.10.3

@krtenn
Copy link

krtenn commented Jul 19, 2021

Just used this in 2021 with latest nginx and worked. (you may need to do something like piping cat <mem_7f7777e77000> > file_to_read_with_vi and then use vi to read that new file. For some reason my text editor would only show raw hex /octals when trying to read these. Not sure if just how I have it set up or missed something. In any case saved me. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment