Apache无法确定[REMOTE_ADDR]

时间:2016-03-24 09:35:41

标签: apache nginx server freebsd

我有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

并尝试从Nginx向Apache发送IP

Nginx conf:

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;
        }
}

但没有成功。

1 个答案:

答案 0 :(得分:0)

Nginx配置看起来不错。您可能需要将以下内容添加到Apache配置中。

RemoteIPHeader X-Client-IP