Nginx server name配置子域名二级域名

绑定子域名到不同目录(子站)

网站的目录结构为

/var/www/html:
├── fx
└── blog
└── photo

html为nginx的默认网站目录。

sudo vi /etc/nginx/sites-available/default

关键代码就两行见红色字体:

server {
listen default_server;
listen [::]: default_server; server_name mongotree.top ~^(?<subdomain>.+)\.mongotree\.top$;
root /var/www/html/$subdomain; # Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html; location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a .
try_files $uri $uri/ =;
} }

sudo /etc/init.d/nginx restart

域名解析配置,子域名解析到主站相同IP就行。

如主站IP是1.1.1.1,添加A记录fx解析到主站IP 1.1.1.1就行。

上一篇:Android View 简析


下一篇:[新手教程]申请https泛域名解析