国产欧美日韩第一页|日本一二三不卡视频|在线精品小视频,亚洲第一免费播放区,metcn人体亚洲一区,亚洲精品午夜视频

linux誤刪nginx.conf文件恢復(fù)方式

2024-05-11 17:43:18 78

linux誤刪nginx.conf文件恢復(fù)方式

藍(lán)隊(duì)云小課堂:

當(dāng)你不小心誤刪或者錯(cuò)誤操作導(dǎo)致nginx.conf文件丟失,而且nginx處于在運(yùn)行的狀態(tài),在這種情況下我們就可以在內(nèi)存中獲取配置文件。

1.獲取nginx進(jìn)程pid

ps -ef | grep nginx

你會(huì)得到如下輸出,找到master的pid

root     19812     1  0 5月10 ?       00:00:00 nginx: master process /usr/sbin/nginx

nginx    19813 19812  0 5月10 ?       00:00:26 nginx: worker process

nginx    19814 19812  0 5月10 ?       00:00:33 nginx: worker process

nginx    19815 19812  0 5月10 ?       00:01:15 nginx: worker process

nginx    19816 19812  0 5月10 ?       00:00:55 nginx: worker process

nginx    19817 19812  0 5月10 ?       00:00:04 nginx: cache manager process

root     26171 12446  0 12:56 pts/0    00:00:00 grep --color=auto nginx

如上所示,nginx的主要進(jìn)程pid為19812

2.查找內(nèi)存映射

安裝gdb工具

yum install gdb -y

接下來(lái)我們需要檢查進(jìn)程正在使用哪些內(nèi)存映射

cat /proc/19812/maps | grep heap


[root@loghub-server tmp]# cat /proc/19812/maps | grep heap

55e0e6760000-55e0e69c2000 rw-p 00000000 00:00 0                          [heap]

可以看到有2處地方,我們只需要關(guān)注heap部分。內(nèi)存位于55e0e6760000-55e0e69c2000之間。

3.轉(zhuǎn)儲(chǔ)堆

然后需要轉(zhuǎn)儲(chǔ)堆

gdb -p 19812

你會(huì)得到一個(gè)(gdb)提示?,F(xiàn)在在這個(gè)提示下使用我們之前記下的地址,地址前需要加0x

(gdb) dump memory /tmp/nginx-memory 0x55e0e6760000 0x55e0e69c2000

4.從轉(zhuǎn)儲(chǔ)中獲取字符串?dāng)?shù)據(jù)

strings  /tmp/nginx-memory > /tmp/nginx-memory.str

5.查找 Nginx 配置

現(xiàn)在有了內(nèi)存轉(zhuǎn)儲(chǔ)。大多數(shù)配置都會(huì)有http {一行,現(xiàn)在可以測(cè)試下/tmp/nginx-memory.str

grep -A 20 "http {" /tmp/nginx-memory.str


[root@loghub-server tmp]# grep -A 50 "http {" /tmp/nginx-memory.str 

http {

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;

    tcp_nopush          on;

    tcp_nodelay         on;

    keepalive_timeout   65;

    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;

    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.

    # See http://www.tjdsmy.cn/en/docs/ngx_core_module.html#include

    # for more information.

    include /etc/nginx/conf.d/*.conf;

    #proxy_temp_path  /etc/nginx/temp_dir;

    #proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=imgcache:100m inactive=1d max_size=1g;

    #proxy_cache_path /etc/nginx/cache_dir levels=1:2 keys_zone=imgcache:500m max_size=1g inactive=1d use_temp_path=off;

    proxy_cache_path /etc/nginx/conf.d/cache levels=1:2 keys_zone=my_zone:100m inactive=3600s max_size=1g;

復(fù)制出來(lái)修改下格式就可以了。

更多小知識(shí),可聯(lián)系藍(lán)隊(duì)云一起探討。


提交成功!非常感謝您的反饋,我們會(huì)繼續(xù)努力做到更好!

這條文檔是否有幫助解決問(wèn)題?

非常抱歉未能幫助到您。為了給您提供更好的服務(wù),我們很需要您進(jìn)一步的反饋信息:

在文檔使用中是否遇到以下問(wèn)題: