Can't reach a Wordpress website through nginx-proxy in Docker

admin

Administrator
Staff member
I'm trying to reach my existing instance of Wordpress through a Docker configuration.

My plan is to have a few websites running on my VPS, so I wanted to go for this Docker setup. First, my
Code:
jwilder/nginx-proxy
file:

Code:
version: '3'

services:
  nginx:
    image: jwilder/nginx-proxy
    container_name: nginx
    restart: always
    labels:
      com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: 'true'
    ports:
      - 80:80
      - 443:443
    volumes:
      - /srv/nginx/data/certs:/etc/nginx/certs:ro
      - /srv/nginx/data/conf.d:/etc/nginx/conf.d
      - /srv/nginx/data/vhost.d:/etc/nginx/vhost.d
      - /srv/nginx/data/html:/usr/share/nginx/html
      - /var/run/docker.sock:/tmp/docker.sock:ro

  letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: letsencrypt
    volumes:
      - /srv/nginx/data/vhost.d:/etc/nginx/vhost.d
      - /srv/nginx/data/certs:/etc/nginx/certs:rw
      - /srv/nginx/data/html:/usr/share/nginx/html
      - /var/run/docker.sock:/var/run/docker.sock:ro
    depends_on:
      - nginx

networks:
  default:
    external:
      name: nginxproxy_default

I run it with
Code:
sudo docker-compose up
and it works great.

Then, I have this other file for <strong>one of my Wordpress projects</strong>:

Code:
version: '3'
services:

  wp:
    image: wordpress:php7.3-fpm
    container_name: wp_my_project
    expose:
      - 3001
    volumes:
      - ./conf/php/conf.d/php.ini:/etc/php/7.3/fpm/php.ini
      - ./conf/php/pool.d/www.conf:/etc/php/7.3/fpm/pool.d/www.conf
    environment:
      - WORDPRESS_DB_NAME=my_project
      - WORDPRESS_TABLE_PREFIX=wp_
      - WORDPRESS_DB_HOST=mysql_my_project
      - WORDPRESS_DB_USER=my_project_user
      - WORDPRESS_DB_PASSWORD=my_project_password
      - VIRTUAL_HOST=test.local
      - VIRTUAL_PORT=3001
      - LETSENCRYPT_HOST=test.local
      - [email protected]
    depends_on:
      - db
    restart: always

  db:
    image: mysql:8.0
    container_name: mysql_my_project
    command: --default-authentication-plugin=mysql_native_password
    volumes:
      - ./mysql:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=whatever
      - MYSQL_USER=root
      - MYSQL_PASSWORD=whatever_again
      - MYSQL_DATABASE=my_project
    restart: always

networks:
  default:
    external:
      name: nginxproxy_default

Before running them, I create network:

Code:
docker network create nginxproxy_default

I have been trying for days without success.

If I go into my
Code:
nginx
docker container using:

Code:
docker exec -it nginx bash

I can see this in the file
Code:
/etc/nginx/conf.d
:

Code:
...
# test.local
upstream test.local {
                ## Can be connected with "nginx-proxy_proxy" network
            # wp_my_project
            server 172.19.0.5:3001;
}
server {
    server_name test.local;
    listen 80 ;
    access_log /var/log/nginx/access.log vhost;
    include /etc/nginx/vhost.d/default;
    location / {
        proxy_pass http://test.local;
    }
}
server {
    server_name test.local;
    listen 443 ssl http2 ;
    access_log /var/log/nginx/access.log vhost;
    return 500;
    ssl_certificate /etc/nginx/certs/default.crt;
    ssl_certificate_key /etc/nginx/certs/default.key;
}
...

It looks OK but all I get when I try to navigate to <strong><a href="http://test.local" rel="nofollow noreferrer">http://test.local</a></strong>, all I get is a <strong>502 error</strong>.

As a final piece of information, I'll provide here the result of:

Code:
docker network inspect nginxproxy_default

Code:
[
    {
        "Name": "nginxproxy_default",
        "Id": "aa332a0666fcf91af535134bb699caeef0eaf03136cc2582c21765fe03b8da31",
        "Created": "2019-06-19T20:28:53.590261887+02:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.22.0.0/16",
                    "Gateway": "172.22.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "3567b10ef6c755ba733571a69a2b14ccc2e10d0a3288346f874cccb23ce9e4fa": {
                "Name": "wp_my_project",
                "EndpointID": "7e7fe30107887b0a2a83c60ac15896eab144294defa6df5ff0a5b0ee2debf40f",
                "MacAddress": "02:42:ac:16:00:03",
                "IPv4Address": "172.22.0.3/16",
                "IPv6Address": ""
            },
            "68a2608c34196bd2e9da20b4edc4d6c7851f27dcd3cf9db03ed2850e3ce4296e": {
                "Name": "nginx",
                "EndpointID": "ce124164464350d736afc94095242914bb7f8b7b59c4884b06c972612a6b8f0e",
                "MacAddress": "02:42:ac:16:00:04",
                "IPv4Address": "172.22.0.4/16",
                "IPv6Address": ""
            },
            "6a87fad4472a37702647b82885ad715acad21701ef992870a2f2cc3490df8a7c": {
                "Name": "mysql_my_project",
                "EndpointID": "71dce4bc75f496e908e4a16e948328fadfa5c4982aeb2898b98f868691465257",
                "MacAddress": "02:42:ac:16:00:02",
                "IPv4Address": "172.22.0.2/16",
                "IPv6Address": ""
            },
            "7518524e7bda2c41664cc46bd4c1d18bf5af09e1d5d2a66557eb49bfc6bff95f": {
                "Name": "letsencrypt",
                "EndpointID": "a15cb4d825cd53acad64cda5070eadc8f97bc5cab1ee45974f967c7da131c2e4",
                "MacAddress": "02:42:ac:16:00:05",
                "IPv4Address": "172.22.0.5/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]