在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Linux/ Docker下的lnmp環(huán)境如何獲取clientIp,和主機Ip。

Docker下的lnmp環(huán)境如何獲取clientIp,和主機Ip。

首先我在Mac下使用docker,docker中使用一個容器安裝lnmp環(huán)境。用戶訪問時,在項目獲取訪問者Ip時,永遠都是172.0.0.1之類的docker橋接的ip,拿不到客戶端ip。谷歌了很久,無法解決。求解
同時也想過去宿主機的ip。謝謝

下面是NGINX配置


listen 80;
server_name www.nihao.test;

location / {
proxy_pass http://www.nihao.test;
                    proxy_set_header    Host             $host:$server_port;#轉發(fā)后端口別忘了
                    proxy_set_header    X-Real-IP        $remote_addr;
                    proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
                    proxy_set_header    HTTP_X_FORWARDED_FOR $remote_addr;#關鍵句
                    proxy_set_header    X-Forwarded-Proto $scheme;
                    proxy_redirect      default;

    try_files $uri $uri/ $uri=404;
}
回答
編輯回答
萌面人

我也遇到這個問題. 直接配置Nginx好像不行的. 2015到2018 這個問題好像一直存在.

通過搜索查到的相關問題

Document how to get real remote client ip for service running in container

nginx 獲取客戶端 IP 實現(xiàn) 根據配置了但無法獲取到真實 IP

network_mode-docker 網絡連接方式

nginx cannot get to client IP

2017年6月17日 06:59