当某人在他的网站上为我的网站创建反向代理时,如何发送重定向请求?

时间:2014-06-17 11:01:39

标签: apache url-rewriting http-redirect

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

例如在apache2中,具有以下行的配置

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

他(坏人)为我的所有内容服务,好像是他的。我该如何防止它。我相信我需要发送一个重定向请求,但是在什么基础上,以及需要什么配置才能做到这一点。目前我有以下内容。我注意到,谷歌做到了这一点,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>

感谢。

1 个答案:

答案 0 :(得分:0)

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

<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之后显示google页面 - 包括我的网站上的搜索结果 - 以及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/

{{1}}

我想,如果谷歌还没有这样做,我不应该为此担心。但是我知道它可能带来的影响。任何人都可以告诉我这会带来什么样的风险?

感谢。