1

I have example.com and the following use cases:

  • SSL only
  • www. will be redirected to example.com (no www.)
  • example.com will reverse proxy to :3000
  • fix1.example.com will reverse proxy to :3001
  • fix2.example.com will reverse proxy to :3002
  • ...
  • *.example.com will reverse proxy to :4000
  • *.example.com/admin will reverse proxy to :5000
    • example.com/admin, fix1.example.com, fix2.example.com,... will not have /admin and must not reverse proxy to :5000

In my current configuration I have the following files in my sites-available / sites-enabled:

  • exmaple.com
  • fix1.example.com
  • fix2.example.com
  • ...
  • wild.example.com

Each file configures his own part as there is no other file. But I end up with duplicate or conflicting configurations, so I'm thinking, there must be a better approach in one file, that handles the entire domain with all use cases.

The SSL only and no www part is easy:

server {
    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
    }
    server_name www.example.com;
    return 301 $scheme://example.com$request_uri;
}
server {
    if ($host = example.com) {
        return 301 https://$host$request_uri;
    }
    listen 80;
    server_name example.com;
    return 301 http://$server_name$request_uri;
}

But how do I set up the fixed subdomains and the wild card subdomain together with the /admin path?

This is the block I use for the example.com proxy:

server {
        listen 443 ssl http2;
        server_name example.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;
        }
        ssl_certificat #...
        ssl_certificat_key #...
}
PhilHarmonie
  • 143
  • 2
  • 7

0 Answers0