nginx 子域名(泛域名)绑定解析到服务器指定目录下
如http://blog.example.com/的请求解析到服务器下的/usr/data/blog/目录中
我们可这样
server { listen 80; server_name *.example.com; access_log /home/wwwlogs/example.com_nginx.log combined; index index.html index.htm index.php; if ($host ~* ^([^\.]+)\.([^\.]+\.[^\.]+)$) { set $subdomain $1; set $domain $2; } location / { root /usr/data/$subdomain/; index index.php index.html index.htm; } location ~ .php$ { fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 7d; } }
网友评论0