如何创build这种types的子域:example.test.domain.com

我设法find一个重写制作子域(我有一个通配符域指向我的服务器; *.domain.com

如果我去test.domain.com ,它工作得很好,横向于:

/var/www/domain.com/www/test/

如果我做example.test.domain.com ,它应该这样做:

/var/www/domain.com/www/test/example/

这是test目录中的另一个目录。

这是我发现使用的重写,但我应该如何实现在这个两个目录子域?

 if ($host !~* ^www\.domain\.domain$) {} if ($host ~* ^([^.]+)\.domain\.com$) { set $auto_subdomain $1; } if (-d /var/www/domain.com/www/$auto_subdomain) {} if (-f /var/www/domain.com/www/$auto_subdomain$uri) { rewrite ^(.*)$ /$auto_subdomain$uri; break; } 

试试/var/www/domain.com/www/example.test/而不是/var/www/domain.com/www/test/example/

更新:其实你试图做的只是第二个虚拟主机,没有更多。 你为什么不试试这个nginxconfiguration?

 server { # Replace this port with the right one for your requirements listen 80 [default|default_server]; #could also be 1.2.3.4:80 # Multiple hostnames separated by spaces. Replace these as well. server_name domain.com test.domain.com example.test.domain.com *.domain.com; # Alternately: _ root /var/www/$host; error_page 404 errors/404.html; access_log logs/star.yourdomain.com.access.log; index index.php index.html index.htm; # serve static files directly location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { access_log off; expires max; } location ~ \.php$ { include fastcgi_params; fastcgi_intercept_errors on; # By all means use a different server for the fcgi processes if you need to fastcgi_pass 127.0.0.1:YOURFCGIPORTHERE; } location ~ /\.ht { deny all; } } 

只需创build每个域/子域的目录即:

 /var/www/domain.com /var/www/test.domain.com /var/www/example.test.domain.com 

资料来源: http : //wiki.nginx.org/VirtualHostExample

还要检查Slicehost有关nginx虚拟主机的HOWTO http://articles.slicehost.com/2008/5/16/ubuntu-hardy-nginx-virtual-hosts

我不认为这将工作与通配符子域。 你应该在* .test.domain.com里添加一个test.domain.com的新区域

参考: http : //en.wikipedia.org/wiki/Wildcard_DNS_record