0

此配置按预期正常工作:

    server {
            listen       80;
            server_name  www.domain1.com domain1.com;

            access_log  /srv/www/domain1.com/logs/access.log;

            location / {
                root   /srv/www/domain1.com/public_html;
                index  index.html index.htm;


    }
    }
    server {
            listen       80;
            server_name  domain2.com www.domain2.com;

            access_log  /srv/www/domain2.com/logs/access.log;

            location / {
                root   /srv/www/domain2.com/public_html;
                index  index.html index.htm;


    }
    }

此配置在访问http://domain2.com时显示来自 domain1 的内容:

    server {
            listen       80;
            server_name  *.domain1.com;

            access_log  /srv/www/domain1.com/logs/access.log;

            location / {
                root   /srv/www/domain1.com/public_html;
                index  index.html index.htm;


    }
    }
    server {
            listen       80;
            server_name  *.domain2.com;

            access_log  /srv/www/domain2.com/logs/access.log;

            location / {
                root   /srv/www/domain2.com/public_html;
                index  index.html index.htm;


    }
    }

我觉得在这两种情况下我都正确地遵循了文档。

在示例二中使用通配符会导致意外行为的原因是什么?

4

1 回答 1

0

*.domain2.com不匹配domain2.com。做:

server_name  domain2.com *.domain2.com;

反而

于 2013-12-13T10:52:14.200 回答