I am facing this issues I am not able to solve by anything I´ve found on this site or anywhere else.

Lets assume I have a domain and Debian server with NGINX installed on it as main gateway for web server. On this domain (on root level) I have a traditional handling (like strippping www, redirecting everytime to https etc - basic stuff).

But now I´d like to have a set of services managed in docker-compose file that will be executed on docker start and these services will be mapped as subdomains to my main domain. Lets assume that domain has set up proper DNS records (these are not problem since I´ve been using subdomains for non docker services with no issues). For simplity take just one service- pgAdmin4- as example

Part of the NGINX configuration that solves this issue is pretty basic.

server {
    listen 80;
    server_name pg.example.com;

    location / {
        proxy_pass http://pgadmin:81; 

Docker compose is even more basic

version: '3.8'
    container_name: pgadmin
    image: dpage/pgadmin4
    restart: always
      PGADMIN_DEFAULT_EMAIL: [email protected]
      - "81:80"

When I try to sudo nginx -t to check the configuration, I am getting an error host not found in upstream "pgadmin"

When I try to replace name of container with host.docker.internal (with extra_hosts in compose set up like "host.docker.internal:host-gateway") or when I try to use or simply localhost:81, I am getting (after restarting NGINX) 502 Bad Gateway whitelabel page error.

In logs I can see a lot of errors like

*2 no live upstreams while connecting to upstream, client:, server: pg.example.com, request: "GET / HTTP/1.1", upstream: "http://localhost/", host: "pg.example.com"

Can anyone tell me what am I doing wrong?

1 Answer 1


Move nginx into Docker (and expose 80/443) using say this container and then set env vars on the containers you want to expose that contain the hostname to map



There is even a companion container that will handle setting up letsencrypt certs on the fly

  • Thanks for answer. Situation is way more complicated and I need to have some host nginx on top and contacting docker containers if needed. There is really no way how to achieve what I need? As I see it, the only problem is how to contact docker container from host
    – Johnczek
    Commented Jun 30, 2023 at 16:17
  • If you poke around that project it probably has all the parts you need, it will just be a bit of effort to get it to work, but you should still be able to host static stuff with the container
    – hardillb
    Commented Jun 30, 2023 at 16:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .