FusionAuth / fusionauth-containers

Container definitions for docker, kubernetes, helm, and whatever containers come next!
https://fusionauth.io/
213 stars 68 forks source link

Reverse Proxy Not Working #65

Closed narayanpromax closed 3 months ago

narayanpromax commented 3 years ago

Reverse proxying via caddy doesn't work. It gives 502

CaddyFile Content As below

# replace :80 with your domain name to get automatic https via LetsEncrypt
https://<your_domain> {
  reverse_proxy fusionauth:9011
}
  1. fusionauth is service running in docker
  2. caddy is running as service running in docker with above CaddyFile
mooreds commented 3 years ago

This issue/PR may be worth reviewing, as I think @atakane got this working: https://github.com/FusionAuth/fusionauth-containers/pull/61

atakane commented 3 years ago

Reverse proxying via caddy doesn't work. It gives 502

CaddyFile Content As below


# replace :80 with your domain name to get automatic https via LetsEncrypt

https://<your_domain> {

  reverse_proxy fusionauth:9011

}
  1. fusionauth is service running in docker

  2. caddy is running as service running in docker with above CaddyFile

did you try without the protocol? Caddy wants us to write domain like auth.mydomain.com rather than https://auth.mydomain.com

narayanpromax commented 3 years ago

Yes, i tried.

Actually i copied hasura's caddy part for CaddyFile and docker and replaced necessary params on a different server.

https works in hasura but i tried both before posting here.

Even ip gives 502. Only accessing via :9011 working for now

allochi commented 3 years ago

Hi, did you find a solution for this?

allochi commented 3 years ago

My solution to this challenge, I used docker for everything, hope it works for others. Unfortunately I wasn't able to use DigitalOcean managed database, I always get connection error, but this is another story.

docker-compose.yml

version: "3"

services:
  http:
    image: caddy:latest
    container_name: http
    restart: unless-stopped
    ports:
      - 80:80
      - 443:443
    networks:
      - network
    volumes:
      - $PWD/Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config

  db:
    image: postgres:11.9-alpine
    container_name: db
    environment:
      PGDATA: /var/lib/postgresql/data/pgdata
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    networks:
      - network
    restart: unless-stopped
    volumes:
      - db_data:/var/lib/postgresql/data

  fusionauth:
    image: fusionauth/fusionauth-app:latest
    container_name: fusionauth
    depends_on:
      - db
      - http
    environment:
      DATABASE_URL: ${DATABASE_URL}
      DATABASE_ROOT_USERNAME: ${POSTGRES_USER}
      DATABASE_ROOT_PASSWORD: ${POSTGRES_PASSWORD}
      DATABASE_USERNAME: ${DATABASE_USERNAME}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD}
      FUSIONAUTH_APP_MEMORY: ${FUSIONAUTH_APP_MEMORY}
      FUSIONAUTH_APP_RUNTIME_MODE: production
      SEARCH_TYPE: database
    networks:
      - network
    restart: unless-stopped
    volumes:
      - fa_config:/usr/local/fusionauth/config

networks:
  network:

volumes:
  db_data:
  fa_config:
  caddy_data:
  caddy_config:

Caddyfile

auth.my-domain.com {
    reverse_proxy fusionauth:9011
}
narayanpromax commented 3 months ago

The solution to the problem is network.

I read line by line with @allochi's solution and found this one thing extra

Do take care that caddy and fusionauth are on same network

mooreds commented 3 months ago

@narayanpromax thanks so much for closing the issue after you found a solution.