需求场景
如果需要实现demo演示站。当然不希望每个小项目都去配置域名解析,太麻烦。所以用到了域名泛解析。并且将域名前缀和目录名字对应,根据目录名字即可访问对应的域名,就减少了很多配置。
具体配置(php示例)
server {
listen 80;
server_name ~^(?<subdomain>.+).demo.urcloud.co$;
root /home/demos/$subdomain;
index index.html index.htm index.php;
fastcgi_intercept_errors on;
error_page 404 = /404.html;
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't
# break when using query string
try_files $uri $uri/ =404;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .*\.php(\/.*)*$ {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
include fastcgi.conf;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
deny all;
}
}