代码之家  ›  专栏  ›  技术社区  ›  Kal

阻止指向您的其他域

  •  0
  • Kal  · 技术社区  · 7 年前

    有没有办法防止这种情况发生?

    <IfModule mod_ssl.c>
    <VirtualHost *:443>
            ServerName www.example.com
            DocumentRoot /path/to/site
    
            <Directory /path/to/site/>
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
            </Directory>
    
    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example.com$ [NC]
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    
    RewriteCond %{HTTP_REFERER} .
    RewriteCond %{HTTP_REFERER} !example\.com [NC]
    RewriteCond %{HTTP_HOST} !example.com [NC]
    RewriteRule .? - [F]
    
    ServerName example.com
    ServerAlias www.example.com
    </VirtualHost>
    </IfModule>
    
    0 回复  |  直到 7 年前
        1
  •  -1
  •   Louis Delfieux    7 年前

    Apache使用 Host 主办 对应于apache ServerName ServerAlias ).

    apache2ctl -S ,它将为您提供一个包含以下内容的输出:

    VirtualHost configuration:
    *:80                   is a NameVirtualHost
             default server ip (/etc/apache2/sites-enabled/000-default.conf:1)
             port 80 namevhost ip (/etc/apache2/sites-enabled/000-default.conf:1)
             port 80 namevhost www.example1.com (/etc/apache2/sites-enabled/001-vhost.conf:1)
             port 80 namevhost www.example2.com (/etc/apache2/sites-enabled/002-vhost.conf:1)
    *:443                  is a NameVirtualHost
             default server 127.0.1.1 (/etc/apache2/sites-enabled/default-ssl.conf:2)
             port 443 namevhost 127.0.1.1 (/etc/apache2/sites-enabled/default-ssl.conf:2)
             port 443 namevhost www.example1.com (/etc/apache2/sites-enabled/non-default-ssl.conf:2)
    

    现在想象我的ip是1.1.1.1:

    考虑到这三个 curl 命令:

    1. curl http://1.1.1.1 -H 'Host: www.example1.com'
    1. curl http://1.1.1.1 -H 'Host: www.example2.com'
    1. curl http://1.1.1.1 -H 'Host: www.spoofexample.com'
    

    首先,apache找到相应的 服务器名 在vhost文件中,并使用/etc/apache2/sites enabled/001-vhost.conf来满足请求

    在vhost文件中,并使用/etc/apache2/sites enabled/002-vhost.conf来满足请求

    第三个(您不想要的映射DNS),apache找不到相应的 并使用/etc/apache2/sites enabled/000-default.conf来满足请求

    同样的逻辑也适用于SSL虚拟主机。

    服务器名 ip ,而且没有 在默认SSL vhost中。Apache只是假设 127.0.1.1

    PS2:要使vhost成为默认值,它必须是按名称排序的第一个(000->001->002)。

        2
  •  -1
  •   Jin Thakur    7 年前

    假设我是来自hostgator的abc.com的域名所有者。为了在godaddy.com上托管它,我必须转到域控制器,将godaddy名称服务器放在那里。然后在托管时,我创建了一个同名网站。 https://www.namecheap.com/support/knowledgebase/article.aspx/385/2237/how-to-redirect-a-url-for-a-domain 您是否从本地计算机托管域?

    推荐文章