如何使用mod_remoteip设置nginx反向代理Apache-2.4(php5_module)

时间:2013-11-07 03:05:31

标签: apache nginx proxy

internet -> nginx -> apache-2.4

Remote_Addr打印127.1.1.0而不是客户端IP。我有apache behaind nginx,具有以下设置: nginx.conf:

location / {
        try_files $uri @apache;
        }

location @apache {
        internal;
        proxy_pass http://127.0.0.1:8080;
        include proxy.conf;
        }

location ~ .*\.(php|php5)?$  {
        proxy_pass http://127.0.0.1:8080;
        include proxy.conf;
        }

proxy.conf:

proxy_connect_timeout 300s;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 32k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_redirect off;
proxy_hide_header Vary;
proxy_set_header Accept-Encoding '';
proxy_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

的httpd.conf:

Listen 127.0.0.1:8080
Include conf/extra/httpd-remoteip.conf

的httpd-remoteip.conf:

LoadModule remoteip_module modules/mod_remoteip.so
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy 127.0.0.1

1 个答案:

答案 0 :(得分:2)

sed -i“s @ LogFormat \”%h%l @ LogFormat \“%h%a%l @”/ usr / local / apache / conf / httpd.conf