问题描述
||
我正在尝试设置Mod代理以阻止除特定域外的所有流量。我可以使用ProxyBlock指令将其配置为阻止单个域,并且可以使用ProxyBlock *阻止所有内容。除了一个域,是否有办法阻止所有内容?
谢谢,
-安德鲁
解决方法
在Apache 2.2上,您需要有2个“ 0”部分。
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指令而不是该regexp来反转域名的匹配项。
注意:我从Invert匹配中获得了regexp与regexp
,尝试:
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