0
問題是PHP字段$_SERVER['HTTP_CLIENT_IP']
未在我的以下站點結構中設置,我應如何更正此問題?如何阻止客戶端IP地址在Cloudflare/Docker/NGINX/LAMP站點中迷路?
命名爲 '回' 泊塢窗橋接網絡(後面的CloudFlare的主機上)上靜態IP容器:
- NGINX在容器中運行(172.24.02)
- 的Apache + PHP的容器( 172.24.0.3)
nginx.conf:
location/{
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://172.24.0.3;
}
test.php的
<?php
echo('HTTP_CLIENT_IP: '.$_SERVER['HTTP_CLIENT_IP']);
echo('<br>HTTP_X_FORWARDED_FOR'.$_SERVER['HTTP_X_FORWARDED_FOR']);
echo('<br>REMOTE_ADDR'.$_SERVER['REMOTE_ADDR']);
echo('<br>HTTP_X_FORWARDED'.$_SERVER['HTTP_X_FORWARDED']);
echo('<br>HTTP_FORWARDED'.$_SERVER['HTTP_FORWARDED']);
echo('<br>HTTP_FORWARDED_FOR'.$_SERVER['HTTP_FORWARDED_FOR']);
?>
運行上面的產量:
HTTP_CLIENT_IP:
HTTP_X_FORWARDED_FOR:
REMOTE_ADDR: 172.24.0.2
HTTP_X_FORWARDED:
HTTP_FORWARDED:
HTTP_FORWARDED_FOR:
你是如何配置Nginx和Apache一起工作的? – Devon
HTTP_CLIENT_IP不是標準頭,REMOTE_ADDR是IP的標準,但在代理情況下,您需要設置標頭。爲什麼不打印出所有的頭文件'print_r($ _ SERVER)',而不是打印出與所定義的頭文件不一致的文件。 – Devon
@Devon Apache在端口80上運行在一個容器中,nginx只需將請求轉發給它,並使用上述配置傳遞標頭。我將嘗試您的建議重新打印出整個變量 – James