title: How to configure nginx to host multiple sub-domains
body: <p>I currently have example.com domain set up on NGINX and it works. I'd like to set up a subdomain test.example.com, but after following multiple different instructions I either keep getting 404 or being redirected to main domain. </p>
  
  <p>My server configuration and file-structure look like this:</p>
  
  <pre><code>/usr/local/nginx
  ├── conf
  │   ├── fastcgi_params
  │   ├── includes
  │   ├── nginx.conf
  │   ├── nginx.conf.save
  │   ├── sites
  │   │   ├── example.com.conf
  │   │   ├── test.example.com.conf
  │   ├── uwsgi_params
  │   └── win-utf
  ├── html
  ├── logs
  └── snippets
      ├── ssl-example.com.conf
      └── ssl-params.conf
  
  /var/www
  ├── example.com
  │   └── ...
  └── test.example.com
      └── index.html
  </code></pre>
  
  <p>I've updated DNS records so that  "*.example.com" points to the same IP</p>
  
  <p>Default domain example.com.conf file looks like this: </p>
  
  <pre><code>server {
      listen 80;
      server_name exmaple.com www.example.com;
      return 301 https://$server_name$request_uri;
  }
  server {
      listen 443 ssl;
      server_name example.com;
      ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
      location ~ /.well-known {
          root /var/www/lets-encrypt/example.com;
          access_log off;
          expires max;
          break;
      }
      include /usr/local/nginx/conf/includes/m2-php71.conf;
  }
  </code></pre>
  
  <p>And subdomain test.example.com.conf file:</p>
  
  <pre><code>server {
      listen 80;
      server_name test.example.com;
      return 301 https://$server_name$request_uri;    
  }
  
  server {
      listen 443 ssl;
      server_name test.example.com;
      ssl_certificate /etc/letsencrypt/live/test.example.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/test.exampe.com/privkey.pem;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
      location ~ /.well-known {
          root /var/www/lets-encrypt/test.example.com;
          access_log off;
          expires max;
          break;
      }
      include /usr/local/nginx/conf/includes/m2-php71.conf;
  }
  </code></pre>
  
  <p>when I remove listen 443 part, it redirects to the main domain. </p>
  
  <p>I'd like the request for sub-domain test.example.com to be served from var/www/test.subdomain.com but cant seem to get past 404 error</p>