【问题标题】:How do I send a redirect request when some one creates a reverse proxy for my site on his site ?当有人在他的网站上为我的网站创建反向代理时,我如何发送重定向请求?
【发布时间】:2014-08-07 08:45:03
【问题描述】:

在 apache 或通过任何其他方式,可以代理到我的网站,从而在他的 URL 中显示我的全部内容。

以apache2为例,配置如下

ProxyPass / http://myawesomewebsite.com/
ProxyPassReverse / http://myawesomewebsite.com/

他(坏人)提供我所有的内容,就好像它是他的一样。我该如何预防。我相信我需要发送重定向请求,但在什么基础上,需要什么配置来做到这一点。目前我有以下。我注意到,Google 这样做了,Facebook 也这样做了,其他所有人都这样做。

<VirtualHost *:80>
    ProxyPreserveHost On
    ServerName www.myawesomewebsite.com

    ServerAdmin me@myawesomewebsite.com
    DocumentRoot /var/www/html

    RewriteEngine On
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthCecker.*
    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} !^www\.myawesomewebsite\.com
    RewriteRule . https://www.myawesomewebsite.com%{REQUEST_URI} [R=301,L]

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    ProxyPass /biz/ http://localhost:8080/
    ProxyPassReverse /biz/ http://localhost:8080/

    ProxyPass / http://10.0.0.12/
    ProxyPassReverse / http://10.0.0.12/
</VirtualHost>

谢谢。

【问题讨论】:

    标签: apache url-rewriting http-redirect


    【解决方案1】:

    我可以通过检查配置中的主机名来进行重定向。以下是使用的配置。

    <VirtualHost *:80>
        ServerName www.myawesomewebsite.com
        ServerAdmin me@myawesomewebsite.com
        DocumentRoot /var/www/html
        ProxyPreserveHost On
        <Proxy *>
            Order deny,allow
            Allow from all
        </Proxy>
    
        RewriteEngine   On
        RewriteCond     %{HTTP_USER_AGENT} !^ELB-HealthChecker.*
        RewriteCond     %{HTTP_HOST}   !^www\.myawesomewebsite\.com$ [OR] [NC]
        RewriteCond     %{HTTP:X-Forwarded-Proto} !https [NC]
        RewriteRule     ^(.*)$   https://www.myawesomewebsite.com$1   [R=301,L]
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ProxyPass /biz/ http://10.0.0.12:8080/
        ProxyPassReverse /biz/ http://10.0.0.12:8080/
    
        ProxyPass / http://10.0.0.12/
        ProxyPassReverse / http://10.0.0.12/
    </VirtualHost>
    

    但是,进一步我发现,在启用 ssl a2enmod ssl 并省略 ProxyPreserveHost On 之后,我什至可以显示谷歌页面 - 包括在我的网站上使用以下配置的搜索结果。

    SSLProxyVerify none
    SSLProxyEngine On
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    
    RewriteEngine   On
    RewriteCond     %{HTTP_USER_AGENT} !^ELB-HealthChecker.*
    RewriteCond     %{HTTP_HOST}   !^www\.awesomewebsite\.com$ [OR] [NC]
    RewriteCond     %{HTTP:X-Forwarded-Proto} !https [NC]
    RewriteRule     ^(.*)$   https://www.awesomewebsite.com$1   [R=301,L]
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    ProxyPass / http://www.google.com/
    ProxyPassReverse / http://www.google.com/
    

    我想,如果 Google 还没有这样做,我不应该担心这一点。但是,我确实知道它可能产生的影响。谁能告诉我这可能会带来什么样的风险?

    谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-13
      • 1970-01-01
      • 2019-02-27
      • 2015-09-20
      • 2013-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多