当前位置 主页 > 服务器问题 > Linux/apache问题 >

    LNAMP架构中后端Apache获取用户真实IP地址的2种方法(2)

    栏目:Linux/apache问题 时间:2018-10-07 13:53


    /usr/local/apache/bin/apxs -i -c -n mod_remoteip.so mod_remoteip.c
    2)、修改配置文件:
    复制代码 代码如下:
    vi /usr/local/apache/conf/httpd.conf
    Include conf/extra/httpd-remoteip.conf
    vi /usr/local/apache/conf/extra/httpd-remoteip.conf
    LoadModule remoteip_module modules/mod_remoteip.so
    RemoteIPHeader X-Forwarded-For
    RemoteIPInternalProxy 127.0.0.1
    3)、测试:
    复制代码 代码如下:
    # /usr/local/apache/bin/apachectl -t
    # /usr/local/apache/bin/apachectl restart
    # 看日志
    2、Apache-2.4配置mod_remoteip
    自带mod_remoteip模块不需要安装,只需要修改日志格式
    复制代码 代码如下:
    LogFormat "%h %a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %a %l %u %t \"%r\" %>s %b" common
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedi
    在日志格式中加上%a