Apache 无法确定 [REMOTE_ADDR]
Apache can't determine [REMOTE_ADDR]
我有 FreeBSD 服务器,前端是 Nginx,后端是 Apache 2.4。一切正常,但 Apache 无法检测到 [REMOTE_ADDR],而是显示服务器 IP 地址。
为了解决我的问题,我启用了
LoadModule remoteip_module libexec/apache24/mod_remoteip.so
httpd.conf
的变化
#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
并尝试将 IP 从 Nginx 发送到 Apache
Nginx 配置文件:
server {
server_name example.com www.example.com;
listen 80;
disable_symlinks if_not_owner from=$root_path;
index index.php;
set $root_path /home/user/example.com/public_html;
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
root $root_path;
error_page 404 = @fallback;
}
location / {
proxy_pass http://localhost:81;
proxy_redirect http://localhost:81/ /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
location @fallback {
proxy_pass http://localhost:81;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
}
但是没有成功。
Nginx 配置看起来不错。您可能需要将以下内容添加到您的 Apache 配置中。
RemoteIPHeader X-Client-IP
我有 FreeBSD 服务器,前端是 Nginx,后端是 Apache 2.4。一切正常,但 Apache 无法检测到 [REMOTE_ADDR],而是显示服务器 IP 地址。
为了解决我的问题,我启用了
LoadModule remoteip_module libexec/apache24/mod_remoteip.so
httpd.conf
的变化#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
并尝试将 IP 从 Nginx 发送到 Apache
Nginx 配置文件:
server {
server_name example.com www.example.com;
listen 80;
disable_symlinks if_not_owner from=$root_path;
index index.php;
set $root_path /home/user/example.com/public_html;
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
root $root_path;
error_page 404 = @fallback;
}
location / {
proxy_pass http://localhost:81;
proxy_redirect http://localhost:81/ /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
location @fallback {
proxy_pass http://localhost:81;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
}
但是没有成功。
Nginx 配置看起来不错。您可能需要将以下内容添加到您的 Apache 配置中。
RemoteIPHeader X-Client-IP