Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seeking guidance on redirect loop issue with modified docker-compose.prod.yaml #19

Open
lacafjh opened this issue Jan 25, 2024 · 0 comments

Comments

@lacafjh
Copy link

lacafjh commented Jan 25, 2024

I apologize for reaching out with a question that may not directly contribute to software improvement or bug fixes. I understand that the issue I'm encountering is likely due to modifications I made to the original compose file, rather than a problem with the repository itself.

On my server, I have several services whose ports are set up to forward requests from port 443 to containers via Caddy. As a result, I had to replace the nginx setup provided in the compose file with a configuration that works with the Caddy instance I had previously installed.

Here is my modified docker-compose.prod.yaml file:

version: "3.9"

services:
  spacebar:
    build:
      context: .
      dockerfile: Dockerfile-prod
    restart: unless-stopped
    ports:
      - "3001:3001"
    volumes:
      - spacebar-storage:/exec/persistent/storage
    environment:
      DATABASE: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DATABASE}
      STORAGE_PROVIDER: "file"
      STORAGE_LOCATION: "/exec/persistent/storage/"
      PORT: "3001"
    depends_on:
      db:
        condition: service_healthy

  db:
    image: postgres:15-alpine
    restart: unless-stopped
    environment:
      - POSTGRES_USER=${POSTGRES_USER:?err}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?err}
      - POSTGRES_DB=${POSTGRES_DATABASE:?err}
    ports:
      - '127.0.0.1:5432:5432'
    volumes: 
      - db:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -d ${POSTGRES_DATABASE} -U ${POSTGRES_USER}"]
      interval: 10s
      timeout: 5s
      retries: 5

  spacebar-client:
    build:
      context: .
      dockerfile: Dockerfile-frontend
      args:
        - SERVER_URL=spacebar:3001
    restart: unless-stopped
    ports:
      - "20080:80"
    depends_on: 
      - spacebar

volumes:
  spacebar-storage:
  db:
  nginx-site:
  letsencrypt-folder:

~/.bashrc file:

export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=postgres
export POSTGRES_DATABASE=spacebar
export [email protected]

All other files in the spacebar-server-client-proxy folder are copied to the current directory without modification.

And the Caddy Compose file is as follows:

version: "3.9"

services:
  caddy:
    image: my_caddy:latest
    container_name: caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    environment:
      - UID=1000
      - GID=1000
    volumes:
      - /etc/caddy/Caddyfile:/etc/caddy/Caddyfile:ro
      - /etc/caddy/site:/srv
      - caddy_data:/data
      - caddy_config:/config
    networks:
      - proxy_net
    extra_hosts:
      - "host.docker.internal:host-gateway"

volumes:
  caddy_data:
    external: true
  caddy_config:

networks:
  proxy_net:
    driver: bridge

The Caddyfile is set up like this:

{
        # TLS Options
        # acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
        acme_dns cloudflare {  {  API_TOKEN  }  }

        servers :443 {
                protocol {
                        # experimental_http3
                        # strict_sni_host
                }
        }
        servers :80 {
                protocol {
                        allow_h2c
                }
        }
}

spacebar.my.domain {
        reverse_proxy host.docker.internal:20080 {
        }
}

This Caddy setup has been working correctly for other services, but when I try to access https://spacebar.my.domain/, I encounter the following error:

This page isn’t working right now
spacebar.my.domain redirected you too many times.
Try deleting your cookies.
ERR_TOO_MANY_REDIRECTS

Following a suggestion from GPT, I modified the Caddyfile to:

{
        # TLS Options
        # acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
        acme_dns cloudflare { {  API_TOKEN  } }

        servers :443 {
                protocol {
                        # experimental_http3
                        # strict_sni_host
                }
        }
        servers :80 {
                protocol {
                        allow_h2c
                }
        }
}

spacebar.my.domain {
        reverse_proxy spacebar-client:80 {
        }
}

This was intended to redirect requests within the Docker network. However, I still receive the same ERR_TOO_MANY_REDIRECTS error when attempting to access the domain.

With my limited network knowledge, I have tried various searches and attempts to no avail. I am humbly reaching out to this vibrant community for help: could it be that the forwarding logic within spacebar-client itself is causing this configuration method, which has always worked for me, to no longer be effective?

If you believe this issue is unrelated to spacebar-client, I would appreciate it if you could let me know at your convenience and feel free to close this issue. If you do not have the time to address this, please feel free to leave this issue aside, as I currently have no problem accessing the service using IP:Port. Thank you for taking the time to read this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant