title: Port numbers not hiding in nginx reverse proxy (next js server)
body: <p>I am trying to deploy a next-js app by create-next-app, I have a custom express server like this -</p>
  
  <pre><code>const express = require('express')
  const next = require('next')
  const dev = process.env.NODE_ENV !== 'production'
  const nextApp = next({ dev })
  const handle = nextApp.getRequestHandler()
  
  const fs = require('fs')
  
  nextApp.prepare()
  .then(() =&gt; {
      const server = express ()
  
  
      let port = 3000;
  
      let options = {
          key: fs.readFileSync('some key..', 'utf-8'),
          cert: fs.readFileSync('some cert..', 'utf-8'),
      };
  
  
      server.get(
          ...
      )
  
  
      let app = https.createServer(options, server)
      .listen((port), function(){
      console.log("Express server listening on port " + port);
      });
  
  })
  .catch((ex) =&gt; {
      console.error(ex.stack)
      process.exit(1)
  })
  </code></pre>
  
  <p>I want to deploy this as the website when someone types the URL subdomain.maindomain.com so I saved two nginx configuration files like this - </p>
  
  <p><strong>/etc/nginx/sites-available/default</strong> AND <strong>/etc/nginx/sites-available/subdomain.maindomain.com</strong></p>
  
  <p>the default file contains this</p>
  
  <pre><code>server {
  
      root /var/www/html;
      index index.html index.htm index.nginx-debian.html;
  
      server_name maindomain.com www.maindomain.com;
  
      location / {
              # try_files $uri $uri/ =404;
              proxy_pass http://localhost:3000;
              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;
      }
  
      listen [::]:443 ssl ipv6only=on; # managed by Certbot
      listen 443 ssl; # managed by Certbot
      ssl_certificate /etc/letsencrypt/live/maindomain.com/fullchain.pem;$
      ssl_certificate_key /etc/letsencrypt/live/maindomain.com/privkey.pe$
      include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
      ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
  
  }
  </code></pre>
  
  <p>and the subdomain.maindomain.com file looks like this</p>
  
  <pre><code>server {
  if ($host = www.subdomain.maindomain.com) {
      return 301 https://$host$request_uri;
  } # managed by Certbot
  
  
  if ($host = subdomain.maindomain.com) {
      return 301 https://$host$request_uri;
  } # managed by Certbot
  
  
      listen 80;
      listen [::]:80;
  
      root /var/www/subdomain.maindomain.com/somecodefolder/;
      index index.html index.htm index.nginx-debian.html;
  
      server_name subdomain.maindomain.com www.subdomain.maindomain.com;
  
  
      location / {
  
          proxy_pass http://localhost:3000;
          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;
         # try_files $uri $uri/ =404;
      }
  </code></pre>
  
  <p>}</p>
  
  <p>if I'm typing <a href="https://subdomain.maindomain.com:3000" rel="nofollow noreferrer">https://subdomain.maindomain.com:3000</a>, everything works fine, I see my website running. But when I type <a href="https://subdomain.maindomain.com" rel="nofollow noreferrer">https://subdomain.maindomain.com</a> (without the port number) it shows nothing. How can I get the content I want when I type just the url without the port number. I have tried many combinations, but could'nt do. someone please help i've been trying since 2 days. </p>