title: NGINX: multiple proxy pass for same domain but different ports
body: <p>Here's the situation:</p>
  
  <p>I have up to 500 independent localhost applications all running simultaneously on a server. My router has ports 80, 443, 8000 to 8500 open. My clients can connect to each of the different localhost applications of their choice. My task is to figure out a way to do this, using 1 domain: example.com</p>
  
  <p>It would be nice if I could use a query string to tell NGINX which application to redirect to. For example, if example.com is my domain name, and I have port 443 open to connect to it, it would be nice if I could do something like:</p>
  
  <p><a href="https://example.com?port=8300" rel="nofollow noreferrer">https://example.com?port=8300</a></p>
  
  <p>then NGINX will redirect this request to localhost:8300</p>
  
  <p>if this cannot be done, another solution could be to request:
  <a href="https://example.com:8300" rel="nofollow noreferrer">https://example.com:8300</a></p>
  
  <p>and then NGINX will redirect this request to localhost:8300</p>
  
  <p>my current setup has <a href="https://example.com" rel="nofollow noreferrer">https://example.com</a> on port 443 redirecting to localhost:8080(the NGINX config code:)</p>
  
  <blockquote>
    <p>server {</p>
  
  <pre><code>    server_name example.com;
  
      location / {
              proxy_pass http://localhost:8080/;
      }
  
  listen [::]:443 ssl ipv6only=on; # managed by Certbot
  listen 443 ssl; # managed by Certbot
  ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by
  </code></pre>
    
    <p>Certbot
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by
    Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot</p>
    
    <p>} server {
        if ($host = example.com) {
            return 301 https://$host$request_uri;
        } # managed by Certbot</p>
  
  <pre><code>    listen 80;
      listen [::]:80;
  
      server_name example.com;
  return 404; # managed by Certbot
  </code></pre>
    
    <p>}</p>
  </blockquote>
  
  <p>but I need a range of proxy_pass arguments, and they need to correspond to either a query string or a domain name's port. </p>
  
  <p>I found no documentation or online articles on how to do this. Thanks!</p>