需求:一臺服務器部署多個項目(前端),項目對應不同的二級域名,比如img.luwuer.com,luwuer.com,blog.luwuer.com
轉載自 :https://www.jianshu.com/p/58b890a1c8fb
二級域名結構
### 3個項目的目錄結構
/root/apps/luwuer.com
/root/apps/blog.luwuer.com
/root/apps/img.luwuer.com
nginx配置
server {
listen 80 default_server;
# $1 = 'blog.' || 'img.' || '' ; $3 = 'luwuer.com'
server_name ~* (\w+\.)?(luwuer\.com)$;
root /root/apps/$1$3
location / {
try_files $uri $uri/ /index.html;
index index.html;
}
# include ./img-cache.conf
# error_page 404 /404.html;
# error_page 500 502 503 504 /50x.html;
}