我正在尝试设置 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
Apache 2.4:这对我有用:首先拒绝一切,然后有选择地授予。
ProxyRequests On
ProxyVia Off
AllowCONNECT 443 563 80
<Proxy *>
Require all denied
</Proxy>
<ProxyMatch "^https?://[a-z]*\.?google\.com.*$">
Require all granted
</ProxyMatch>
<ProxyMatch "^[a-z]*\.?google\.com:443$">
Require all granted
</ProxyMatch>
注意 HTTPS 需要第二个 ProxyMatch(带 :443),否则您的请求将获得:
Received HTTP code 403 from proxy after CONNECT
意味着你的 https 通过了,但是 SSL 隧道被拒绝了。
这适用于 Apache 侦听:80,使用以下请求
curl -x localhost:80 "https://www.google.com?q=mod_proxy&language=de"
但不与
curl -x localhost:80 "https://www.bing.com?q=google.com"
这是必不可少的,否则您可以通过伪造的查询字符串参数来绕过白名单。