2016-05-01 136 views
1

例如,我有一个域example.com,当用户注册时,web应用程序将创建子域。如何从通配符域中排除特定的子域(Nginx)

  • 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 config

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?

回答

2

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

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

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