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.