我正在尝试设置 mod 代理以阻止除特定域之外的所有流量。我可以使用 ProxyBlock 指令将其配置为阻止单个域,并且可以使用 ProxyBlock * 阻止所有内容。有没有办法阻止除一个域之外的所有内容?
谢谢,
-安德鲁
在 apache 2.2 上,您需要有 2 个proxy
部分。
ProxyRequests On
ProxyVia On
# block all domains except our target
<ProxyMatch ^((?!www\.proxytarget\.com).)*$>
Order deny,allow
Deny from all
</ProxyMatch>
# here goes your usual proxy configuration...
<ProxyMatch www\.proxytarget\.com >
Order deny,allow
Deny from all
Allow from 127.0.0.1
</ProxyMatch>
在 apache 2.4 上它会容易得多,因为您可以使用If 指令而不是该正则表达式来反转域名的匹配。
尝试:
ProxyBlock *
ProxyPass <path> <destination>
看看这是否有效。
编辑:从头开始。我认为您必须在这里使用 mod_rewrite 发挥创意(基本参考位于http://httpd.apache.org/docs/current/rewrite/proxy.html):
RewriteCond %{HTTP_HOST} =allowtoproxy.com
RewriteRule ^/(.*)$ http://proxytarget.com/$1 [P]
ProxyPassReverse / http://proxytarget.com/
试试看?
试试这个代码:
RewriteEngine On
# Testing URLs
RewriteCond %{HTTP_HOST} !google.co.uk [NC]
RewriteCond %{HTTP_HOST} !bbc.co.uk [NC]
RewriteCond %{HTTP_HOST} !amazon.com [NC]
RewriteCond %{HTTP_HOST} !centos.org [NC]
RewriteCond %{HTTP_HOST} !opensuse.org [NC]
# Url to redirect to if not in allowed list
RewriteRule (.*) http://example.org/notallowed.htm