Skip to content

Instantly share code, notes, and snippets.

@wendal
Created April 11, 2012 12:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wendal/2359053 to your computer and use it in GitHub Desktop.
Save wendal/2359053 to your computer and use it in GitHub Desktop.
nginx二级域名自动匹配为子文件夹(通过rewrite)
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name nutz.cn *.nutz.cn;
set $sub_domain "";
if ($http_host ~ "(.+).nutz.cn$") {
set $sub_domain $1;
}
if ($http_host = "www.nutz.cn") {
set $sub_domain "";
}
if ($sub_domain != "") {
rewrite /(.+) /$sub_domain/$1 break;
}
location / {
root html;
index index.html index.htm;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment