[SOLVED] My wordpress container is accessible on his own but not through my Nginx container

Hi, I’m new to docker :slight_smile:.

I work on a VM (Ubuntu 18) on my Win10 laptop.

On this VM I have 3 docker containers created with docker-compose.

The first docker-compose.yml (wordpress + sql)

version: '3.1'
services:
    wordpress:
        depends_on:
            - mysql
        image: wordpress
        restart: always
        ports:
            - 8080:80  
        environment:
            VIRTUAL_HOST: wordpressalex_wordpress_1.local
            VIRTUAL_PORT: 8080
            WORDPRESS_DB_PASSWORD: *

    mysql:
       image: mysql:5.7
       restart: always
       environment:
           MYSQL_ROOT_PASSWORD: *

networks:
    default:
        external:
            name: nginx-network

And the second for nginx in a different folder

version: '2'
services:
    nginx-proxy:
        image: jwilder/nginx-proxy
        ports:
            - "80:80" 
        volumes:
            - /var/run/docker.sock:/tmp/docker.sock:ro

networks:
    default:
        external:
            name: nginx-network

I can access the wordpress container via http://[ip of the VM]:8080/

But when I hit http://[ip of the VM]/ I get a 503 Service Temporarily Unavailable from Nginx.

When I hit http://wordpressalex_wordpress_1.local/ (that I’ve added to my Windows 10 etc/hosts) I get this answer :

Bad Request
Your browser sent a request that this server could not understand.
Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request.

docker ps : all my containers are UP and running.
docker network inspect nginx-network : the 3 containers are in the network with an IP.
The nginx service is active but I get no logs (I’ve already changed the error_logs to debug in the nginx.conf)
In the Nginx docker container, the config has been auto made by jwilder/nginx-proxy :

...
upstream wordpressalex_wordpress_1.local {
    server 172.18.0.4:80;
}
server {
    server_name wordpressalex_wordpress_1.local;
    listen 80;
    ...
    location / {
        proxy_pass http://wordpressalex_wordpress_1.local
    }
}

How can I reverse-proxy my Wordpress container with Nginx ?

I’ve been on it for 2 days, I’ve made the process from scratch at least 5 times, with jwilder/nginx-proxy and with official nginx image and a Docker file, even with a non dockerized Nginx, I think I’m missing something :slight_smile:
Thanks for reading me

Okay, the problem seems to be that your wordpress container is listening on port 80, but you have configured nginx-proxy to reach it at port 8080.

When nginx-proxy reaches a container, it uses the container port, not a mapped port. In fact, you should not map the port at all. What that means is that you should re-write the first compose file as follows:

version: '3.1'
services:
    wordpress:
        depends_on:
            - mysql
        image: wordpress
        restart: always
        environment:
            VIRTUAL_HOST: wordpressalex_wordpress_1.local
            VIRTUAL_PORT: 80
            WORDPRESS_DB_PASSWORD: *

    mysql:
       image: mysql:5.7
       restart: always
       environment:
           MYSQL_ROOT_PASSWORD: *

networks:
    default:
        external:
            name: nginx-network

Notice how we are using 80 in VIRTUAL_PORT? That should do the trick.

Also, access this using http://wordpressalex_wordpress_1.local. nginx-proxy works by using the host name to route the request to another container. If you use an IP address, nginx-proxy won’t know where to route the request, and you will get a 503 error.

1 Like

@rajchaudhuri

Thanks alot for your time, the problem is solved . :slight_smile: