NGINX Subdomains

No Comments

In the example below we serve index.html from /var/www/html/your_site directory when accessing “domain.com”; and we send all requests to local application server running locally on port 4000 when accessing subdomain.domain.com

File: /etc/nginx/sites-enabled/default

server {
        listen 80;
        listen [::]:80;

        server_name domain.com;

        location / {
                root /var/www/html/your_site;
                try_files $uri /index.html;
        }
}

server {
  listen 80;
  listen [::]:80;

  server_name subdomain.domain.com;

  location / {
     proxy_redirect off;
     proxy_pass http://127.0.0.1:4000/;
  }
}
Categories: Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Loading Facebook Comments ...