分类: nginx

  • 如何从正在跑着的nginx里读到它正在使用的配置文件内容

    来源:在nginx跑着的时候手贱把配置文件盖了,我想既然nginx既没重启也没重新读配置,所以肯定有什么办法dump出来当前正在用的配置文件。

    然后搜了下搜到一个直接用gdb读内存的法子,来源https://serverfault.com/questions/361421/dump-nginx-config-from-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_*

    改一下pid为主进程的pid即可,然后退出gdb,去mem_*文件里搜配置文件的关键字。