有这样的需要,有主域名www.test.com,要求提供给其它人申请二级域名,使别人可以使用类似于xxx.test.com(实际对应于www.test.com/xxx),应该怎么实现呢?
对于这种不确定的二级域名的情况,可以使用到泛域名解析的技术。
泛域名解析,在dns中就是增加一条新的纪录:
*:泛解析,匹配其他所有域名 *.test.com
对于这种不确定的二级域名的情况,可以使用到泛域名解析的技术。
泛域名解析,在dns中就是增加一条新的纪录:
*:泛解析,匹配其他所有域名 *.test.com
然后在nginx中配置:
server {
listen 80; ## listen for ipv4; this line is default and implied
root /var/www/test;
index index.php index.html index.htm;
server_name *.suntenart.com;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
if ( $http_host ~* "^(.*?)\.suntenart\.com$")
{
set $domain $1;
}
location / {
if ($domain !~* ^www$)
{
rewrite ^/(.*) /$domain break;
}
}
}
[文章作者]曾健生
[作者邮箱]zengjiansheng1@126.com
[作者QQ]190678908
[博客] http://blog.youkuaiyun.com/newjueqi