Apache2 反向代理 proxy设置

1、加载apache模块proxy, proxy_http

2、配置vhost

ProxyPreserveHost On
ProxyPass / http://127.0.0.1/
ProxyPassReverse / http://127.0.0.1/

3、为了获取到原始ip,有几种方法,

A、从header里的x-forwarded-for获取到代理前的IP地址

B、使用Apache的remoteip模块

配置

                  RemoteIPHeader X-Forwarded-For
                  RemoteIPInternalProxy 127.0.0.1

日志格式中加%a

LogFormat “%v:%p %h %a %l %u %t \”%r\” %>s %O \”%{Referer}i\” \”%{User-Agent}i\”” vhost_combined
LogFormat “%h %a %l %u %t \”%r\” %>s %O \”%{Referer}i\” \”%{User-Agent}i\”” combined
LogFormat “%h %a %l %u %t \”%r\” %>s %O” common