[英]Detect apache reverse proxy programmatically
我想使用两个具有不同主机名(虚拟主机)的不同反向代理通过Apache 2.4代理一个网站-我们称其为“ APP”。 我们将这些代理称为“ Alfa”和“ Beta”。 我希望Alfa成为显示网站正常版本的“公共代理”。 Beta代理将限制对某些客户端IP的公共访问,但是我想在网站的每个页面顶部显示某种类型的敏感信息。 让我们将敏感信息的那些部分称为“ SENS”。
这是我当前的apache配置。
Listen 443
NameVirtualHost *:443
SSLStrictSNIVHostCheck off
## Virtual host for the Alfa Proxy
<VirtualHost *:443>
ServerName alfa.mysite.org
RewriteEngine On
<Location /app/>
ProxyPass http://x.x.x.x:8080/app/
ProxyPassReverse http://x.x.x.x:8080/app/
</Location>
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile conf/alfa.crt
SSLCertificateKeyFile conf/alfa.key
</VirtualHost>
## Virtual host for the Beta Proxy
<VirtualHost *:443>
ServerName beta.mysite.org
RewriteEngine On
<Location /app/>
Require ip 192.168.0
ProxyPass http://x.x.x.x:8080/app/
ProxyPassReverse http://x.x.x.x:8080/app/
</Location>
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile conf/beta.crt
SSLCertificateKeyFile conf/beta.key
</VirtualHost>
为了仅向Beta用户显示SENS,我需要以编程方式检测哪些代理请求来自。 现在,我研究了反向代理请求标头的使用,例如“ X-Forwarded-Server”。 假设我在APP中定义了某种安全过滤器(例如Spring过滤器),该过滤器仅在X-Forwarded-Server等于“ beta.mysite.org”时才允许在页面上呈现SENS。 这应该很好。
但是我的问题是:我是否可以确定不会对代理标头进行某种形式的篡改,从而使alfa.mysite.org用户实际查看我网站的SENS部分?
如果是这样,还有其他方法可以做到“安全”。 我想避免使用两个不同版本的APP或将APP部署在两个不同的容器上。
任何意见或建议,表示赞赏。
根据Apache文档,当使用多个代理时,x-forwarded-server标头可以是逗号分隔的列表。 因此,从安全角度来看,我认为它不安全。
在您不直接访问后端服务器的假设下,您可以尝试以下操作。 设置自己的HTTP标头,该值根据传递的VirtualHost的不同而变化。 然后,您只需要检查后端是否存在标头即可。
ServerName alfa.mysite.org
RewriteEngine On
<Location /app/>
#Set - The request header is set, replacing any previous header with this name
RequestHeader set MyCustomHeader "remote"
</Location>
ServerName beta.mysite.org
RewriteEngine On
<Location /app/>
Require ip 192.168.0
#The request header is set, replacing any previous header with this name
RequestHeader set MyCustomHeader "local"
..
</Location>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.