綁定子域名到不同目錄(子站)
網站的目錄結構為
/var/www/html:
├── fx
└── blog
└── photo
html為nginx的默認網站目錄。
sudo vi /etc/nginx/sites-available/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就行。