nginx.tmpl config is wrong: proxy_pass {{ trim $proto }} results in 502 Bad Gateway between containers

Author: IAMtheIAMCreated Jul 4, 2019Updated Jun 20, 2026

https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion/blob/621798e92235b6eb75e0d34d3b6209dfee96ff7d/nginx.tmpl#L284

This line of code has a problem. the proxy_pass {{ trim $proto }}://{{ trim $upstream_name }}; causes an issue. {{ trim $proto }} translates into https and this causes the 502 Bad Gateway error. If I change it to proxy_pass http://{{ trim $upstream_name }}; then immediately my new container is found by nginx and loads correctly.

Why is this variable used here and how is it supposed to work using https? Because let's say my docker container runs on localhost:3000 internally, and externally I'm running on 443 https and proxy_pass sends it over to localhost:3000 - well there's nothing telling localhost to serve over https, so it fails. Please explain the logic here and I Will PR if needed. It must use http for internal proxy_pass requests.