My team was trying to update nginx config, sites-available/mysite.com
, when he was trying to save it suddenly the file can not be saved, due to the disk size problem and now the file is empty (size is 0). Is there any way to create a new config file based on current nginx conf? The nginx server haven't restarted yet since the file is edited, hence, it still works fine and we don't have the latest backup of sites-available/mysite.com
file, thus I prefer to restore current config which exist in the memory.
Thank you.
First of all before attempting this make sure now you have enough space free on your server and you will need to have sudo rights as well.
Finding the main nginx process
The first thing you need is to find the main process of nginx
As you can see my main nginx process is
3890
pid.Finding the memory map Next we need to check what memory maps the process is using
Now there will be a lot of output, but don't worry we mainly interested in the
[heap]
section. The memory is located at556990d72000-556990dd5000
.Dumping the heap
Now you need to dump the heap. Make sure you have
gdb
installed. Connect to the process usingYou will get a
(gdb)
prompt. Now on this prompt use the addresses that we noted earlierGetting string data out of dump
Now our dump is available at
/tmp/nginx-memory
, now we need to get string data out of itFinding the Nginx Config
Now you have a memory dump. Most configs will have a
http {
line and now you can test your/tmp/nginx-memory.str
for the sameSo look into this file carefully and recover you config and create a new one