---
title: "nginx泛域名解析"
author: "flowercat"
date: "2010-04-05T22:11:46Z"
tags: []
categories: ["互联网"]
slug: "nginx"
draft: false
lastmod: "2010-04-05T22:11:46Z"
id: 633743
url: "https://flowercat.iteye.com/blog/633743"
---

在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 ;  
}