转载

从运行中的nginx 中找到nginx.conf

最近生产环境中的一个nginx的配置文件被误覆盖了(删除还能恢复,覆盖恢复太困难了),google了一下,有从/proc中
dump mem 的方式,不能说完全恢复,但是全部运行的server_name都能找到,附上作者原话:

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.

大意是:你应该得到一些像 “mem_086cb000” 类似的二进制文件 。在编辑器中打开这个文件,搜索配置(例如“worker_connections”指令),复制和粘贴。

更新:这个方法并不完全可靠。它是基于:假设nginx在运行过程中会读取配置和不覆盖/不再利用该存储区。我想这是主nginx的进程中给了我们最好的机会。
方法如下(希望能帮到有需要的人):
找到运行中的nginx主进程号
# 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_*

然后用vi或vim打开这个mem_*文件查找server_name即可。
另外可以用vi -b mem_* 打开,再用:%!xxd  转换成16进制,查找server_name即可。
比较方便的是下载到本地,用一下二进制阅读工具来搜索查看,会友好一些。

From: http://serverfault.com/questions/361421/dump-nginx-config-from-running-process/436239
正文到此结束
Loading...