Multiple SWAG instances on single machine

I was hoping to host multiple sites/domains from a single machine and give each site it’s own SWAG container/instance.

  1. Does anyone know if this is a supported configuration?
  2. If this is a supported configuration, do you know of any examples I could look at for reference?

Best way to handle this is having multiple WAN IP’s to assign for each site. Otherwise you’d need to host all the sites in 1 instance but they would share all the same ssl cert.

What I’ve tried so far:

  • run docker-hoster so that I can route to each container by name

    $ docker run -d     -v /var/run/docker.sock:/tmp/docker.sock     -v /etc/hosts:/tmp/hosts     dvdarias/docker-hoster
    
  • run nginx on the machine, giving each site it’s own config:

    • config for site 1:

      server {
          listen 80;
          server_name test.site1.com;
      
          location ~ ^/(.*) {
              rewrite /(.*) /$1  break;
              include proxy_params;
              proxy_pass http://site1-container;
          }
      
          error_log  /var/log/nginx/site1-error.log;
          access_log /var/log/nginx/site1-access.log;
      }
      
      server {
          listen 443;
          server_name test.site1.com;
      
          location ~ ^/(.*) {
              rewrite /(.*) /$1  break;
              include proxy_params;
              proxy_pass https://site1-container;
          }
      
          error_log  /var/log/nginx/site1.log;
          access_log /var/log/nginx/site1.log;
      }
      
    • config for site 2:

      server {
          listen 80;
          server_name test.site2.com;
      
          location ~ ^/(.*) {
              rewrite /(.*) /$1  break;
              include proxy_params;
              proxy_pass http://site2-container;
          }
      
          error_log  /var/log/nginx/site2-error.log;
          access_log /var/log/nginx/site2-access.log;
      }
      
      server {
          listen 443;
          server_name test.site2.com;
      
          location ~ ^/(.*) {
              rewrite /(.*) /$1  break;
              include proxy_params;
              proxy_pass https://site2-container;
          }
      
          error_log  /var/log/nginx/site2.log;
          access_log /var/log/nginx/site2.log;
      }
      
  • spin up site 1’s container (a simple non-swag web server which works):

    $ docker run --name site1-container -d site1-image
    
  • spin up site 2’s container with the following yml file:

    ---
    version: "2.1"
    services:
      site2db:
        image: ghcr.io/linuxserver/mariadb
        container_name: site2db
        environment:
          - TZ=America/Toronto
          - MYSQL_ROOT_PASSWORD=a
          - MYSQL_DATABASE=b
          - MYSQL_USER=c
          - MYSQL_PASSWORD=d
        volumes:
          - /var/apps/site2/db:/config
        restart: unless-stopped
      site2:
        image: ghcr.io/linuxserver/swag
        container_name: site2-container
        environment:
          - TZ=America/Toronto
          - URL=site2.com
          - SUBDOMAINS=test
          - VALIDATION=http
        volumes:
          - /var/apps/site2/swag:/config
        depends_on:
          - site2db
        restart: unless-stopped
    

I get success when visiting http://test.site1.com
but I get “502 Bad Gateway” when visiting http://test.site2.com

Any tips would be super helpful!

i would recommend getting two wan IPs, one pointing 80/443 to each swag instance. your site2 swag probably isn’t even starting since you’re using http validation without port 80 being passed to it.

Hi Guys,
I will pin my question, here so not to start new thread. Since obviously there is no way to run simultaneously multiple swags on the same host, is there another way to set multiple domains in one swag to get multiple domains in one certificate?

yes, the readme covers how to do this already.

extra domains

I checked the docs but not sure how I missed it.
Thanks, @driz

@MikeBusuttil
since there is a way to get multiple domains in one swag you can achieve what you were hoping for to host multiple domains on the same host
the principle is simple:
One main swag that will have ports 80/443 ported will manage certificate requests for all domains and subdomains, also host one of the domains and act as a proxy to all other domains.
other containers don’t have to be linuxserver swag can be any other http server, but you need to remember to use different ports for each of the server instance, so for example second http server would have http/https mapped to example 80001/44301 and then you proxy secondary domain from main swag to http://127.0.0.1:80001 and do the same for all further domains
You can also proxy http services from other servers/nodes as well just need to use their IP address instead localhost (127.0.0.1)