Grav container not accessible from SWAG container

I’m trying to serve Grav from the Linuxserver Grav container (port 80 mapped to 8080) from nginx running in a SWAG container, but I get a 502 Bad Gateway error.

Both containers are running on a VPS with domain

I can access the Grav instance if I access the container’s port directly, i.e.

I can ping the Grav container from the SWAG container (“ping grav”), but I get “connection refused” if I try to curl the Grav container on the exposed port (curl grav:8080).

I can successfully curl the SWAG container from the Grav container (curl swag:80).

Any suggestions on how to troubleshoot this?

1 Like

I’ve checked all the common reasons for 502 listed in that document:

  • both containers are in the same docker compose yaml, so they are on the same network
  • the container names are the default grav and swag
  • I made sure the external port I specified in the docker compose yaml matches with the one specified in the nginx config file
  • the contents of the /config/nginx/resolver.conf file is “resolver valid=30s;” as expected

Here is the grav block of my docker compose file:

container_name: grav
- PUID=1000
- PGID=1000
- TZ=America/Vancouver
- appdata/grav:/config
- 4443:443
- 8080:80
restart: unless-stopped

And here is the location block of the relevant proxy config file:

    include /config/nginx/proxy.conf;
    include /config/nginx/resolver.conf;

    set $upstream_app grav;
    set $upstream_port 8080;
    set $upstream_proto http;

    proxy_pass $upstream_proto://$upstream_app:$upstream_port;

Change upstream_port back to 80 and restart, that will fix it

Note that this is exactly what bullet 3 says, you manually changed the port in the config. You shouldn’t have :stuck_out_tongue:

Ah I completely misunderstood the meaning of that bullet point :face_with_open_eyes_and_hand_over_mouth:

I did more reading and now understand that it’s the internal container port that needs to be defined as $upstream_port since it’s connecting to the container directly.

Thanks to all for setting me straight!

All good, we are all learning! Glad you got it sorted

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