Mastodon behind Swag Proxy

I am trying to follow various tutorials on setting up a Mastodon stack. I am using Swag as my reverse proxy, and cannot get my mastodon.subdomain.conf file to work. Is there anyone who has gotten Mastodon working with Swag? I’m getting a “502 Bad Gateway” error.

My conf file:

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

    server_name mast.example.net;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location / {
        try_files $uri @proxy;
    }

    location ~ ^/(emoji|packs|system/accounts/avatars|system/media_attachments/files) {
        add_header Cache-Control "public, max-age=31536000, immutable";
        try_files $uri @proxy;
    }

    location /sw.js {
        add_header Cache-Control "public, max-age=0";
        try_files $uri @proxy;
    }

    location @proxy {
        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app mastodon_web_1;
        set $upstream_port 3005;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;

        proxy_set_header Range $http_range;
        proxy_set_header If-Range $http_if_range;
    }

    location /api/v1/streaming {
        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app mastadon_streaming_1;
        set $upstream_port 4005;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;
    }

}

docker-compose.yml

version: "2.4"
services:

  web:
  #    build: .
    image: tootsuite/mastodon
    restart: always
    env_file: .env.production
    command: bash -c "rm -f /mastodon/tmp/pids/server.pid; bundle exec rails s -p 3000"
    networks:
      mastodon:
      BACKBONE:
    healthcheck:
      test: ["CMD-SHELL", "wget -q --spider --header 'x-forwarded-proto: https' --proxy=off localhost:3000/api/v1/instance || exit 1"]
    ports:
      - "127.0.0.1:3005:3000"
    depends_on:
      - mastodon_postgres
      - mastodon_redis
    #  - es
    volumes:
      - ./public/system:/mastodon/public/system

  streaming:
  #    build: .
      image: tootsuite/mastodon
      restart: always
      env_file: .env.production
      command: node ./streaming
      networks:
        mastodon:
        BACKBONE:
      healthcheck:
        test: ["CMD-SHELL", "wget -q --spider --header 'x-forwarded-proto: https' --proxy=off localhost:4000/api/v1/streaming/health || exit 1"]
      ports:
        - "127.0.0.1:4005:4000"
      depends_on:
        - mastodon_postgres
        - mastodon_redis

  sidekiq:
  #    build: .
    image: tootsuite/mastodon
    restart: always
    env_file: .env.production
    command: bundle exec sidekiq
    depends_on:
      - mastodon_postgres
      - mastodon_redis
    networks:
      mastodon:
      BACKBONE:
    volumes:
      - ./public/system:/mastodon/public/system

  mastodon_postgres:
    image: postgres:latest
    container_name: mastodon_postgres
    environment:
      POSTGRES_DB: mastodon
      POSTGRES_USER: mastuser
      POSTGRES_PASSWORD: mastpass
    volumes:
      - ./config/data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
    restart: always
    networks:
      mastodon:

  mastodon_redis:
    image: redis:latest # The official Redis docker image
    container_name: mastodon_redis
    command: redis-server --appendonly yes --appendfsync everysec
    volumes:
      - ./redisconfig/data:/data
    healthcheck:
      test: ["CMD-SHELL", "redis-cli", "ping"]
    restart: unless-stopped
    networks:
      mastodon:

networks:
  mastodon:
    internal: true
  BACKBONE:
    external:
      name: BACKBONE_network