Nginx Reverse-Proxy configuration with Docker Containers

  configuration, docker, nginx, reverse-proxy

since few days I play around with NGINX and Docker. I try to configure the NGINX as Proxy for other services, but I got stacked. Let me explain my problem. as first I have several Docker container running on a Ubuntu Server 20 LTS together configured in a custom network called services.

docker network create -d bridge --subnet= services

Then I run a container for MySQL, PhpMyAdmin, Apache2/PHP7 and Nginx. Here are the commands how I created the containers:

docker run -d --name mysql --restart=always 
--net services --ip 
-v /home/mysql/data:/var/lib/mysql 
-v /home/mysql/conf:/etc/mysql 

docker run -d --name phpmyadmin --restart=always 
-p 8000:80 --net services --ip 
-v /home/sql:/etc/phpmyadmin/sql 
-v /home/ 

docker run -d --name lamp-7.4 --restart=always 
-p 8002:80 -p 587 -p 25 -p 465 -p 443 -p 3306 --net services --ip 
-v /home/htdocs:/var/www/html 
-v /home/apache:/etc/apache2 
-v /home/php:/usr/local/etc/php 

docker run -d --name nginx --restart=always 
-p 80:80 -p 587 -p 25 -p 465 -p 443 -p 8002 -p 8000 -p 8090 --net services --ip 
-v /home/nginx:/etc/nginx/conf.d 

Every container is working fine, as long I connect direct by the Server IP (not the container IP). Lets say this I is: On the Apache Server running 2 WordPress installations called site and site2. That means I reach those Installations by the URI

The PhpMyAdmin is reachable by the URI:

Now I have my domain is reachable by the Nginx container. My Nginx config file default.config:

server {
    listen       80;
    listen  [::]:80;
    charset UTF-8;
    gzip on;
    access_log off;
    rewrite_log on;
    error_log /var/log/nginx/error.log error;

    location /dba/ {
        proxy_buffering off;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        # proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        proxy_read_timeout 60;

I’m no able to find a configuration the Services are reachable by he following URI:

I already opened all defined ports in my providerss (IONOS, Cloud Server) configuration and the Domain Cache is set to 1 Minute.

Each variation of the proxy configuration I tried was not working well. In the best case I was able to see for the login page, but after login I got a redirect to without the path /dba/. after I added this manually it was working. After playing around some days without any success I’m desperate and also a bit lost. Because if I made the correct redirection then I need to enable SSL. The certificates I got from my provider I really hope to find here some help. Thanks a lot in advanced.

Source: Docker Questions