如何设置Apache 2.2的基本身份validation绕过IP? 我已经按照这个维基http://wiki.apache.org/httpd/BypassAuthenticationOrAuthorizationRequirements ,但总是要求一个密码,也列入IP:
<Directory /var/www/html/mydir> AuthName "Private" AuthType Basic AuthUserFile "/etc/httpd/htpasswd" Require valid-user Order allow,deny Allow from 111.111.111.111 222.222.222.222 Satisfy any </Directory>
我在haproxy下,但我设置了IP,我已经设置LogFormat这样:
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
access_log是:
111.111.111.111 - - [25/Oct/2016:12:35:41 +0200] "GET /index.html HTTP/1.1" 401 487 "-" "Mozilla/5.0 (X11; Linux armv7l; rv:38.0) Gecko/20100101 Firefox/38.0 Iceweasel/38.7.0"
你configuration很好,很标准。 如果您使用的是haproxy那么所有请求的源IP地址是haproxy本身,这是检查allow from指令的IP地址,而不是X-Forwarded-For标头的内容。
有几种方法可以解决这个问题。 使用Apache v2.2,您可以使用第三方模块,如mod_custom_headers( http://support.en.ctx.org.cn/ctx109555.citrix,对不起,原来的citrix页面似乎已经移动或被删除)或可能mod_rpaf (我以前没有使用它,所以不能确定它是否会导致allow from正常工作)。
这些模块修改了Apache关于请求所持有的数据,以便源IP成为由您的代理(例如X-Forwarded-For )设置的命名头的值。
或者,您可以升级到Apache v2.4并使用mod_remoteip,它可以做同样的事情。
请注意,还有一个Apacheconfiguration解决scheme,您可以在haproxy上设置自己的头(或者,如果您信任,可以使用X-Forwarded-For一个头)。 就像是:
SetEnvIf X-Forwarded-For ^111.111.111.111 access_granted_by_ip SetEnvIf X-Forwarded-For ^222.222.222.222 access_granted_by_ip Order allow,deny Allow from env=access_granted_by_ip
但是我承认这对于多个IP地址来说有点笨拙。