nginx泛域名解析

在dns做一条泛指到主机上,利用nginx做二级域名的rewirte

例如music.afen.cn/index.php?id=1转到www.afen.cn/music/index.php?id=1

server {
listen       80;
server_name www.afen.cn;
access_log  off;
root /usr/www/afen/;

location / {
index  index.php index.html index.htm;
}

}

server {

server_name ~^(.*)\.afen\.cn$;
set $name $1;
rewrite ^ http://www.afen.cn/$name$request_uri ;
}

猜你喜欢

转载自flowercat.iteye.com/blog/633743