首先需要在域名管理处做一个泛解析 把*.domain.com 指向你自己的服务器的ip,然后在Nginx配置文件里面增加配置,这个配置还可以制作三级域名,例如*.demo.domain.com.
# domain.com
server {
listen 80;
server_name ~^(?.+)\.domain\.com$;
charset utf-8;
access_log logs/domain.com.access.log main;
error_log logs/domain.com.error.log;
root /web/data/www/$subdomain;
index index.php index.html index.htm;
fastcgi_intercept_errors on;
error_page 404 = /404.html;
location / {
try_files $uri $uri/ =404;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1/ last;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ .*\.php(\/.*)*$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}