2011-05-25 19 views

回答

5

在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 directive而不是正则表达式的反转匹配的域名。

注意:我从Invert match with regexp得到该正则表达式

0

尝试:

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/ 

尝试吗?

+0

这不起作用。任何其他想法? – abudker 2011-05-25 20:36:22

0

试试这个代码:

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 
相关问题