I am trying to set up a local Wordpress environment using Docker Compose with Nginx reverse proxy. WordPress. works but in Site Health I get:
Error: cURL error 28: Resolving timed out after 10000 milliseconds (http_request_failed)
This my docker-compose file
version: '3.1'
services:
web:
image: nginx
ports:
- "80:80"
volumes:
- ./site.conf:/etc/nginx/conf.d/site.conf
depends_on:
- wordpress
- db
wordpress:
image: wordpress
expose:
- 80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: local_user
WORDPRESS_DB_PASSWORD: secret
WORDPRESS_DB_NAME: local
volumes:
- ./wordpress:/var/www/html
db:
image: mysql:5.7
environment:
MYSQL_DATABASE: local
MYSQL_USER: local_user
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: root_secret
ports:
- 3306:3306
volumes:
- ./mysql:/var/lib/mysql
this is my Nginx config file:
upstream backend{
server wordpress:80;
}
server {
listen 80;
listen [::]:80;
index index.php index.html;
server_name bedrock.local;
# error_log /var/log/nginx/error.log;
# access_log /var/log/nginx/access.log;
# root /code/web;
location / {
proxy_pass http://backend/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
bedrock.local domain resolves locally with 127.0.0.1 in /etc/hosts I'm not using HTTPS (just HTTP) to simplify the test.
Thanks!
I had the same issue, Wordpress container cannot reach the website on the public IP address due to the Docker networking.
The best solution to this is to add the fqdn aliases to the Nginx container in the docker-compose.yml file to allow Wordpress to reach Nginx internally.
This config will solve the issue:
web:
image: nginx
ports:
- "80:80"
volumes:
- ./site.conf:/etc/nginx/conf.d/site.conf
depends_on:
- wordpress
- db
networks:
default:
aliases:
- yourwebsite.com
- www.yourwebsite.com