Skip to main content

Adding a Sub Domain Configs to NGINX

This is the process I follow to add a site config to my NGINX reverse proxy server, which is Debian 12, and the following commands should work for any Debian based distro. Adjust fire according to your flavor, as needed.

On the NGINX reverse proxy server, create a new site config and name it appropriately, then add the following and save the file. I tend to create my site configs in /etc/nginx/sites-available.

server { 
  listen 80; 
  server_name sub.domain.com; 
  return 301 https://$host$request_uri; 
} 

server { 
  listen 443 ssl; 
  server_name sub.domain.com; 
  # SSL certificate and key configuration for the host 
  ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem; 
  ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem; 
  # Add your SSL configuration for the host here (e.g., SSL protocols, ciphers, etc.) 

  location / { 
  proxy_pass http://192.168.0.XXX; # Internal IP address of the container 
  proxy_set_header Host $host; 
  proxy_set_header X-Real-IP $remote_addr; 
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
  proxy_set_header X-Forwarded-Proto $scheme; 
  }
}

With that config saved (be sure to add any other specific use case items as needed), execute the following command to create symbolic link:

ln -s /etc/nginx/sites-available/CONFIG-FILE-NAME /etc/nginx/sites-enabled/
nginx -t

If no errors return and NGINX doesn't complain about your config file, restart NGINX with this:

systemctl restart nginx