502 Bad Gateway when using provided docker-compose.yml

Hello! I’ve been trying to host Gramps Web on an Amazon Linux EC2 instance. I’m able to stand up the server without issue, and register the owner account, but when I try to use the web app itself, most things will cause an alert to come up, showing Error: Error 502. Some pages, such as the map, are completely blank. The browser’s console is full of 502 Bad Gateway errors for all the requests to /api, and I get lines like the following in the logs for the nginx-proxy:

 *25 no live upstreams while connecting to upstream, client: xxx.xxx.xxx.xxx, server: my.domain.com, request: "GET /api/users/ HTTP/2.0", upstream: "http://my.domain.com/api/users/", host: "my.domain.com", referrer: "https://my.domain.com/settings"

My configuration is as follows:

nginx_proxy.conf

client_max_body_size 500m;

docker-compose.yml

version: "3.7"

services:
  grampsweb: &grampsweb
    container_name: grampsweb
    image: ghcr.io/gramps-project/grampsweb:latest
    restart: always
    environment:
      GRAMPSWEB_TREE: "Gramps Web"  # will create a new tree if not exists
      VIRTUAL_PORT: "5000"
      VIRTUAL_HOST: my.domain.com  # e.g. gramps.mydomain.com
      LETSENCRYPT_HOST: my.domain.com   # e.g. gramps.mydomain.com
      LETSENCRYPT_EMAIL: my@email.com  # your email
      GRAMPSWEB_CELERY_CONFIG__broker_url: "redis://grampsweb_redis:6379/0"
      GRAMPSWEB_CELERY_CONFIG__result_backend: "redis://grampsweb_redis:6379/0"
      GRAMPSWEB_RATELIMIT_STORAGE_URI: redis://grampsweb_redis:6379/1
      GUNICORN_NUM_WORKERS: 2
    volumes:
      - gramps_users:/app/users
      - gramps_index:/app/indexdir
      - gramps_thumb_cache:/app/thumbnail_cache
      - gramps_cache:/app/cache
      - gramps_secret:/app/secret
      - gramps_db:/root/.gramps/grampsdb
      - gramps_media:/app/media
      - gramps_tmp:/tmp
    networks:
      - proxy-tier
      - default

  grampsweb_celery:
    <<: *grampsweb  # YAML merge key copying the entire grampsweb service config
    container_name: grampsweb_celery
    depends_on:
      - grampsweb_redis
    command: celery -A gramps_webapi.celery worker --loglevel=INFO

  grampsweb_redis:
    image: redis:alpine
    container_name: grampsweb_redis
    restart: always

  proxy:
    image: nginxproxy/nginx-proxy
    container_name: nginx-proxy
    restart: always
    ports:
      - 80:80
      - 443:443
    environment:
      ENABLE_IPV6: "true"
    volumes:
      - ./nginx_proxy.conf:/etc/nginx/conf.d/my_proxy.conf:ro
      - conf:/etc/nginx/conf.d
      - dhparam:/etc/nginx/dhparam
      - certs:/etc/nginx/certs:ro
      - vhost.d:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - /var/run/docker.sock:/tmp/docker.sock:ro
    networks:
      - proxy-tier

  acme-companion:
    image: nginxproxy/acme-companion
    container_name: nginx-proxy-acme
    restart: always
    environment:
      NGINX_PROXY_CONTAINER: nginx-proxy
    volumes:
      - certs:/etc/nginx/certs:rw
      - vhost.d:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
      - acme:/etc/acme.sh
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - proxy-tier
    depends_on:
      - proxy

volumes:
  acme:
  certs:
  conf:
  dhparam:
  vhost.d:
  html:
  gramps_users:
  gramps_index:
  gramps_thumb_cache:
  gramps_cache:
  gramps_secret:
  gramps_db:
  gramps_media:
  gramps_tmp:

networks:
  proxy-tier:

None of the containers other than nginx-proxy show any errors in their logs (except grampsweb not being able to find some media files referenced in the tree I uploaded, which I imagine is unrelated). Any help is appreciated; thank you!

Hi, it could be a problem with your DNS setup, please check the acme-companion docs. 502 always comes from nginx. Are you accessing the site through https://my.domain.com?

I’ll take a look at them! Maybe someone has reported a similar issue over there. And yes, accessing through https://my.domain.com.

Oh wait. I think there is an error in the docs.

  grampsweb_celery:
    <<: *grampsweb  # YAML merge key copying the entire grampsweb service config

I think this actually doesn’t work with the acme-companion setup because it will assign the same VIRTUAL_PORT to the celery container! Can you please replace the << line by the copy of all the stuff from the grampsweb service except the env vars starting with VIRTUAL or LETSENCRYPT?

1 Like

Just tried that, and it seems to have done the trick! No more alerts popping up, and the only errors in the console log correspond to images that didn’t get uploaded to Gramps Web. Thanks you so much for the help!

1 Like

Great! I fixed the example.

I suspect this might also have been the underlying issue of @TheOtherGuy in Setup Issues: Gramps Web on VPS with SSL - #26 by SNoiraud