【问题标题】:Why does using the wildcard signifier for a second "server_name" break my nginx config为什么使用通配符表示第二个“server_name”会破坏我的 nginx 配置
【发布时间】:2013-12-11 23:26:41
【问题描述】:

此配置按预期正常工作:

    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;


    }
    }

我觉得我在这两种情况下都正确地关注了docs

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

【问题讨论】:

  • 如果您希望您的网站显示为domain2.com,请删除星号。这意味着您需要拥有server_name .domain1.com;server_name .domain2.com;

标签: nginx wildcard server-name


【解决方案1】:

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

server_name  domain2.com *.domain2.com;

改为

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-21
    • 2014-11-25
    • 1970-01-01
    • 2012-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多