0

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'
services:
  pgadmin:
    container_name: pgadmin
    image: dpage/pgadmin4
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: pw
    ports:
      - "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 127.0.0.1:81 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: 78.136.141.1, 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?
Johnczek
  • 101
  • 2

1 Answers1

0

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

e.g.

VIRTUAL_HOST=foo.example.com

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

hardillb
  • 1,552
  • 2
  • 12
  • 23
  • 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 Jun 30 '23 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 Jun 30 '23 at 16:43