Two containers of the same app - gives 502

Hi,
I have two containers running Home Assistant, which I can access on my local network.
Cut from docker-compose.yml

  homeassistant:
    image: lscr.io/linuxserver/homeassistant:latest
    container_name: homeassistant
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=<my timezone>
    volumes:
      - <paths>
    ports:
      - 8123:8123
    restart: unless-stopped

and

  ha-bs:
    image: lscr.io/linuxserver/homeassistant:latest
    container_name: homeassistant-bergostrand
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=<my timezone>
    volumes:
      - <paths>
    ports:
      - 8124:8123
    restart: unless-stopped

In nginx/proxy-confs I have the file
homeassistant.subdomain.conf

## Version 2021/10/11
# make sure that your dns has a cname set for homeassistant and that your homeassistant container is not using a base url

# As of homeassistant 2021.7.0, it is now required to define the network range your proxy resides in, this is done in Homeassitants configuration.yaml
# https://www.home-assistant.io/integrations/http/#trusted_proxies
# Example below uses the default dockernetwork ranges, you may need to update this if you dont use defaults.
#
# http:
#   use_x_forwarded_for: true
#   trusted_proxies:
#     - 172.16.0.0/12

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name <mysubdomain>.*;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    # enable for ldap auth, fill in ldap details in ldap.conf
    #include /config/nginx/ldap.conf;

    # enable for Authelia
    #include /config/nginx/authelia-server.conf;

    location / {
        # 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
        #auth_request /auth;
        #error_page 401 =200 /ldaplogin;

        # enable for Authelia
        #include /config/nginx/authelia-location.conf;

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

    }

    location ~ ^/(api|local|media)/ {
        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app homeassistant;
        set $upstream_port 8123;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;
    }
}

I can access this all fine.

Given this success, I thought it would be piece of cake to make my second home assistant container available via Nginx. Just make a copy of homeassistant.subdomain.conf, adjust name and port, and I’m done!
But here I am hours later writing this post…

The file homeassistant-bergostrand.subdomain.conf

## Version 2021/10/11
# make sure that your dns has a cname set for homeassistant and that your homeassistant container is not using a base url

# As of homeassistant 2021.7.0, it is now required to define the network range your proxy resides in, this is done in Homeassitants configuration.yaml
# https://www.home-assistant.io/integrations/http/#trusted_proxies
# Example below uses the default dockernetwork ranges, you may need to update this if you dont use defaults.
#
# http:
#   use_x_forwarded_for: true
#   trusted_proxies:
#     - 172.16.0.0/12

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name bergostrand.*;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    # enable for ldap auth, fill in ldap details in ldap.conf
    #include /config/nginx/ldap.conf;

    # enable for Authelia
    #include /config/nginx/authelia-server.conf;

    location / {
        # 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
        #auth_request /auth;
        #error_page 401 =200 /ldaplogin;

        # enable for Authelia
        #include /config/nginx/authelia-location.conf;

        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app homeassistant-bergostrand;
        set $upstream_port 8124;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;

    }

    location ~ ^/(api|local|media)/ {
        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app homeassistant-bergostrand;
        set $upstream_port 8124;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;
    }
}

Trying to access bergostrand.(mydomain) just gives me a Nginx 502.

Restarted Swag multiple times, tried replacing “-” with “_” in the container name and filename. Didn’t help.

When I look at the Swag log, I notice that the second container (homeassistant-bergostrand) is not listed as an an outdated date, although it should as it has the same date as .

swag                 | **** This may be due to user customization or an update to the samples. ****
swag                 | **** You should compare the following files to the samples in the same folder and update them. ****
swag                 | **** Use the link at the top of the file to view the changelog. ****
swag                 | ┌────────────┬────────────┬────────────────────────────────────────────────────────────────────────┐
swag                 | │  old date  │  new date  │ path                                                                   │
swag                 | ├────────────┼────────────┼────────────────────────────────────────────────────────────────────────┤
swag                 | │ 2021-04-21 │ 2022-08-20 │ /config/nginx/authelia-location.conf                                   │
swag                 | │ 2021-09-19 │ 2022-08-20 │ /config/nginx/ssl.conf                                                 │
swag                 | │ 2021-04-27 │ 2022-10-03 │ /config/nginx/site-confs/default.conf                                  │
swag                 | │ 2021-10-26 │ 2022-09-01 │ /config/nginx/proxy.conf                                               │
swag                 | │ 2021-05-28 │ 2022-09-22 │ /config/nginx/authelia-server.conf                                     │
swag                 | │ 2021-10-11 │ 2022-09-08 │ /config/nginx/proxy-confs/homeassistant.subdomain.conf                 │
swag                 | │ 2021-05-18 │ 2022-09-08 │ /config/nginx/proxy-confs/photoprism.subdomain.conf                    │
swag                 | │ 2020-06-02 │ 2022-08-20 │ /config/nginx/ldap-server.conf                                         │
swag                 | │ 2022-01-09 │ 2022-08-16 │ /config/nginx/nginx.conf                                               │
swag                 | └────────────┴────────────┴────────────────────────────────────────────────────────────────────────┘

So it seems that Nginx isn’t picking up my homeassistant-bergostrand config at all.
(My photoprism container also works fine via Nginx)

Tried searching the forum, and thought this would help me: https://discourse.linuxserver.io/t/swag-multiple-container-instances-502/3258, but no…

I’m out of ideas of what could be wrong.

Slept on it, and after another hour of fiddeling around, if figured it out.
The solution is in the documentation (SWAG - LinuxServer.io):

Keep in mind that the port listed here is the container port because nginx is connecting to this container directly via the docker network. So if our mytinytodo container has a port mapping of -p 8080:80 , we still set $upstream_port variable to 80 .

So when I copied the config file, I shouldn’t have changed the port.
Problem solved.

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