How to configure mod_proxy to block each site except one

I am trying to configure mod proxy to block all traffic except a specific domain. I can configure it to block individual domains using the ProxyBlock directive, and I can block everything using ProxyBlock *. Is there a way to block everything except one domain?

Thank,

-Andrew

+3
source share
3 answers

In apache 2.2 you need to have 2 partitions 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>

On apache 2.4, this would be a lot easier, because you could use If directive regexp instead to invert the match for the domain name.

.

+5

Try:

ProxyBlock *
ProxyPass <path> <destination>

, .

EDIT: . , 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

Try this code:

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
0
source

All Articles