【问题标题】:How to configure mod_proxy to block every site except one如何配置 mod_proxy 以阻止除一个以外的所有站点
【发布时间】:2011-09-02 00:53:52
【问题描述】:

我正在尝试设置 mod 代理来阻止除特定域之外的所有流量。我可以使用 ProxyBlock 指令将其配置为阻止单个域,并且可以使用 ProxyBlock * 阻止所有内容。有没有办法阻止除一个域之外的所有内容?

谢谢,

-安德鲁

【问题讨论】:

    标签: proxy apache mod-proxy


    【解决方案1】:

    在 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 得到那个正则表达式

    【讨论】:

      【解决方案2】:

      试试:

      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/
      

      试试看?

      【讨论】:

        【解决方案3】:

        试试这个代码:

        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
        

        【讨论】:

          猜你喜欢
          • 2016-11-06
          • 2014-04-04
          • 2011-09-21
          • 1970-01-01
          • 1970-01-01
          • 2017-12-24
          • 1970-01-01
          • 2012-06-25
          • 2011-11-15
          相关资源
          最近更新 更多