Nginx server name配置子域名二级域名
v5captain 人气:0绑定子域名到不同目录(子站)
网站的目录结构为 /var/www/html: ├── fx └── blog
└── photo
html为nginx的默认网站目录。
sudo vi /etc/nginx/sites-availablehttps://img.qb5200.com/download-x/default
关键代码就两行见红色字体:
server { listen 80 default_server; listen [::]:80 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 404. try_files $uri $uri/ =404; }
}
sudo /etc/init.d/nginx restart
域名解析配置,子域名解析到主站相同IP就行。
如主站IP是1.1.1.1,添加A记录fx解析到主站IP 1.1.1.1就行。
加载全部内容