server {
listen 80;
server_name ~^(?<subdomain>[a-z0-9\-]*?)\.(?<domain>[a-z0-9\-]*?\.(?:com|cn|net|org|gov|info|la|cc|co|hk)(?:\.(?:cn|jp))?)$;
root /www/webpub/$web_path;
index index.html index.htm index.php;
set $web_path $domain/$subdomain;
if ($subdomain = phpmyadmin) {
set $web_path phpmyadmin;
}
access_log /www/wwwlogs/$subdomain.$domain.log combined;
location ~ ^/.+\.php {
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 1h;
}
}
智能配置,一个conf搞定所有站,已知问题:对没加www.的域名,如xxx.com无法访问,可以通过域名解析跳转到带www的域名。
几点说明:
(1)/www/webpub与/www/wwwlogs,网站目录与网站日志目录,改成你自己的。
(2)phpmyadmin为所有站点共用目录,解析二级域名或者本地改hosts指向phpmyadmin.xxx.com即可用phpmyadmin管理数据库。
(3)不支持不带www的域名访问,高手请完善下正则判断