如何配置mod_proxy阻止除一个站点之外的所有站点

问题描述

|| 我正在尝试设置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
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...