Skip to Content
πŸ“ NotesπŸ’» DeploymentLinuxNginxAdvance - Sub Domain Split Setting

Sub Domain Split Setting

Assume you have understand to baisc concepts of sub domain. You may split all your setting into multi-files for better management.

File structure:

The follow structure is to split two sub-domain.

πŸ“‚ . β”œβ”€β”€ default β”œβ”€β”¬ πŸ“‚ conf.d β”‚ β”œβ”€β”€ blog.sample.me.conf β”‚ └── www.sample.me.conf

Default 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-Domaiin 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 is assume what you are doing RP 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 th following cammand to check if your serrings 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 restart
Last updated on