【问题标题】:apache2 mod_remoteip x-forwarded-for .htaccessapache2 mod_remoteip x-forwarded-for .htaccess
【发布时间】:2016-10-05 19:58:45
【问题描述】:

设置如下:

负载均衡器后面的网络服务器,

负载均衡器通过 x-forwarded-for 发送 client-ip,

mod_remoteip 在网络服务器上激活并按预期工作。

配置:remotip.conf

RemoteIPHeader X-Forwarded-For

问题:

一些(图像)目录通过 .htaccess-file 和 mod_rewrite 保护:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http(s)?://([a-z0-9]+\.)*my\.referer\.com(/)?.*$ [NC]
RewriteCond %{REMOTE_HOST}  !1.2.3.4 [NC] 
RewriteRule \.(jpe?g|gif|png)$ - [F,NC]

仅在引荐来源网址正确 (my.referer.com) 或远程 IP (1.2.3.4) 适合的情况下才会提供图片。

不幸的是,这不适用于 mod_remoteip 激活!我尝试使用%{HTTP_FORWARDED}, %{X-Forwarded-For} or %{HTTP:X-Forwarded-For} 而不是%{REMOTE_HOST},但没有任何效果。见Server-Variables in

http://httpd.apache.org/docs/current/mod/mod_rewrite.html

如果我通过

添加本地负载均衡器 IP(即 10.0.0.1)
RewriteCond %{REMOTE_HOST}  !10.0.0.1 [NC]

图像已交付。但是现在,每个人都可以看到图像了……

我希望有人有办法解决它!

trace6- apache2 日志:

[Wed Oct 05 12:03:40.490129 2016] [rewrite:trace3] [pid 13245] mod_rewrite.c(468): [client 1.2.3.4:38165] 10.0.0.1 - - ...

我认为mod_rewrite不使用客户端ip!

【问题讨论】:

    标签: .htaccess mod-rewrite apache2 load-balancing


    【解决方案1】:

    这是解决方案

    使用

    %{REMOTE_ADDR}
    

    而不是

    %{REMOTE_HOST}
    

    【讨论】:

      猜你喜欢
      • 2013-10-22
      • 1970-01-01
      • 1970-01-01
      • 2017-01-07
      • 2017-09-27
      • 2019-03-09
      • 2016-08-14
      • 2019-11-30
      相关资源
      最近更新 更多