【问题标题】:How to exclude a specific subdomain from wildcard domain (Nginx)如何从通配符域(Nginx)中排除特定子域
【发布时间】:2016-08-26 01:19:47
【问题描述】:

例如,我有一个域 example.com,当用户注册时,Web 应用程序会创建子域。

  • foo.example.com 将指向同一个站点
  • bar.example.com 将指向同一个网站

但我想创建一个测试环境,例如demo.example.com 将指向另一个项目。当用户注册时,它将拥有

  • foo.demo.example.com
  • bar.demo.example.com

目前我所拥有的

| Name           | Type  | Value           |
|----------------|-------|-----------------|
| example.com.   | A     | 123.123.123.123 |
| *.example.com. | CNAME | example.com.    |

还有我的 nginx 配置

server {
    listen 80;

    root /var/www/example.com/public;
    index index.html index.htm index.php;
    server_name example.com *.example.com;

    location / {
       try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

如何为测试环境创建 1 个?

【问题讨论】:

    标签: nginx wildcard-subdomain


    【解决方案1】:

    您需要创建一个新的服务器块,其中子域 fqdn 作为 server_name,nginx 将遵循此优先顺序。

    1. 确切名称
    2. 以星号开头的最长通配符名称,例如“*.example.org”
    3. 以星号结尾的最长通配符名称,例如“邮件。*”
    4. 第一个匹配的正则表达式(按配置文件中出现的顺序)

    更多信息:http://nginx.org/en/docs/http/server_names.html

    【讨论】:

      猜你喜欢
      • 2016-05-04
      • 2020-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-18
      • 1970-01-01
      相关资源
      最近更新 更多