Sub-Domain Split Setting
Assume you understand the basic concepts of subdomains. You may split all your settings into multiple files for better management.
File structure:
The following structure is used to split two subdomains.
π .
βββ default
βββ¬ π conf.d
β βββ blog.sample.me.conf
β βββ www.sample.me.confDefault settings
default
server {
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name sample.me; # Your basic domain
location / {
try_files $uri $uri/ =404;
}
}
## Add this line, and create a folder named "conf.d"
include /etc/nginx/sites-available/conf.d/*.conf;Sub-Domain settings
- For
www.sample.me.conf
www.sample.me.conf
server{
server_name www.sample.me; # Sub-domain name
}- For
blog.sample.me.conf
blog.sample.me.conf
server{
server_name blog.sample.me; # Sub-domain name
client_max_body_size 100M;
# Optional, this assumes you are using a reverse proxy
location / {
proxy_pass http://localhost:8084;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}Final checking
Run the following command to check if your settings are correct, then reload the config.
# Check is config correct
sudo nginx -t
# Hot reload
sudo service nginx reload
# Reload with services (Optional)
sudo service nginx restartLast updated on