SWAG + Multiple Container Instances = 502

I am having an issue trying to set up multiple instances of Sonarr (one default instance, and one for 4K) under separate subfolders using SWAG. I’m pretty sure it’s something to do with the modifications I’ve made to the proxy-config for the second Sonarr instance. I’ve done my best but it’s really not my area of strength (yet!).

Compose:

---
version: "2.1"
services:
  swag:
    image: ghcr.io/linuxserver/swag
    container_name: swag
    cap_add:
      - NET_ADMIN
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=<my timezone>
      - URL=<my domain>
      - SUBDOMAINS=wildcard
      - VALIDATION=dns
      - CERTPROVIDER=zerossl
      - DNSPLUGIN=cloudflare #optional
      #- DUCKDNSTOKEN=<token> #optional
      - EMAIL=<my email address>
      #- ONLY_SUBDOMAINS=false #optional
      #- EXTRA_DOMAINS=<extradomains> #optional
      #- STAGING=false #optional
    volumes:
      - /opt/appdata/swag_config:/config
    ports:
      - 443:443
      #- 80:80 #optional
    restart: unless-stopped
  sonarr:
    image: ghcr.io/linuxserver/sonarr
    container_name: sonarr
    environment:
      - UMASK=002
      - PUID=1000
      - PGID=1000
      - TZ=<my timezone>
    volumes:
      - /opt/appdata/sonarr_config:/config
      - /mnt/data:/data #to allow atomic moves
      #- /path/to/tvseries:/tv #optional
      #- /path/to/downloadclient-downloads:/downloads #optional
    ports:
      - 8989:8989
    restart: unless-stopped
  sonarr_4k:
    image: ghcr.io/linuxserver/sonarr
    container_name: sonarr_4k
    environment:
      - UMASK=002
      - PUID=1000
      - PGID=1000
      - TZ=<my timezone>
    volumes:
      - /opt/appdata/sonarr_4k_config:/config
      - /mnt/data:/data #to allow atomic moves
      #- /path/to/tvseries:/tv #optional
      #- /path/to/downloadclient-downloads:/downloads #optional
    ports:
      - 8990:8989
    restart: unless-stopped

First Sonarr Proxy Config:

## Version 2021/05/18
# first go into sonarr settings, under "General" set the URL Base to /sonarr and restart the sonarr container

location ^~ /sonarr {
    # enable the next two lines for http auth
    #auth_basic "Restricted";
    #auth_basic_user_file /config/nginx/.htpasswd;

    # enable the next two lines for ldap auth, also customize and enable ldap.conf in the default conf
    #auth_request /auth;
    #error_page 401 =200 /ldaplogin;

    # enable for Authelia, also enable authelia-server.conf in the default site config
    #include /config/nginx/authelia-location.conf;

    include /config/nginx/proxy.conf;
    include /config/nginx/resolver.conf;
    set $upstream_app sonarr;
    set $upstream_port 8989;
    set $upstream_proto http;
    proxy_pass $upstream_proto://$upstream_app:$upstream_port;

}

location ^~ /sonarr/api {
    include /config/nginx/proxy.conf;
    include /config/nginx/resolver.conf;
    set $upstream_app sonarr;
    set $upstream_port 8989;
    set $upstream_proto http;
    proxy_pass $upstream_proto://$upstream_app:$upstream_port;

}

Second Sonarr Proxy Config

## Version 2021/05/18
# first go into sonarr settings, under "General" set the URL Base to /sonarr and restart the sonarr container

location ^~ /sonarr-4k {
    # enable the next two lines for http auth
    #auth_basic "Restricted";
    #auth_basic_user_file /config/nginx/.htpasswd;

    # enable the next two lines for ldap auth, also customize and enable ldap.conf in the default conf
    #auth_request /auth;
    #error_page 401 =200 /ldaplogin;

    # enable for Authelia, also enable authelia-server.conf in the default site config
    #include /config/nginx/authelia-location.conf;

    include /config/nginx/proxy.conf;
    include /config/nginx/resolver.conf;
    set $upstream_app sonarr_4k;
    set $upstream_port 8990;
    set $upstream_proto http;
    proxy_pass $upstream_proto://$upstream_app:$upstream_port;

}

location ^~ /sonarr-4k/api {
    include /config/nginx/proxy.conf;
    include /config/nginx/resolver.conf;
    set $upstream_app sonarr_4k;
    set $upstream_port 8990;
    set $upstream_proto http;
    proxy_pass $upstream_proto://$upstream_app:$upstream_port;

}

I have made sure to set the url base in the second Sonarr instance to “/sonarr-4k” under settings/general/host. The port number remains 8989 but I think this is necessary because if I change it to 8990 I lose access via the local IP address.

I realise that it might be preferable from a security standpoint to have everything behind a VPN but I do find it useful being able to pop in every so often on devices that don’t have a VPN (i.e. it cant be installed on them).

As the containers are using docker networking, you can leave the ports as they within the config and only need to change the $upstream_app, Change the port back to 8989 for the second instance and it should work just fine (you don’t need to change anything in the compose port section)

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.