I am trying to setup a production environment for multiple WordPress sites using Docker, Nginx reverse proxy, and Let's Encrypt.
I have 3 containers for the proxy group using the jwilder/docker-gen, jwilder/nginx-proxy, and jrcs/letsencrypt-nginx-proxy-companion images.
I also have separate containers for mysql and WordPress.
Everything runs ok and the site loads. However, I am getting the following Site Health Errors in WordPress:
The REST API request failed due to an error. Error: cURL error 28: Connection timed out after 10000 milliseconds (http_request_failed)
The loopback request to your site failed, this means features relying on them are not currently working as expected. Error: cURL error 28: Connection timed out after 10001 milliseconds (http_request_failed)
Background updates ensure that WordPress can auto-update if a security update is released for the version you are currently using.
Warning Could not confirm that the wp_version_check() filter is available
I have confirmed that cURL is working within the WordPress container and also that all containers are on the same docker network.
I have tried disabling all plugins in WordPress and using default theme (twentytwenty).
I am able to update plugins and themes.
I can't say that there is something specifically NOT working, however, I would like all Site Health tests to pass. This same site runs on a LAMP stack and all Site Health tests pass.
I will mention that the site also seems slower to respond when running in the Docker container.
I am thinking that this must have something to do with Nginx, but I cannot figure out what it could be. Any help would be greatly appreciated.
Included are my docker-compose.yml configurations.
For Nginx:
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
# environment:
# - VIRTUAL_PROTO=https
# - VIRTUAL_PORT=443
volumes:
- /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
- /srv/nginx/data/certs:/etc/nginx/certs:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
networks:
- proxy
dockergen:
image: jwilder/docker-gen
container_name: dockergen
command: -notify-sighup nginx -watch /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
volumes:
- /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
- /srv/nginx/data/certs:/etc/nginx/certs:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro
networks:
- proxy
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: letsencrypt
depends_on:
- nginx
- dockergen
environment:
NGINX_PROXY_CONTAINER: nginx
NGINX_DOCKER_GEN_CONTAINER: dockergen
volumes:
- /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
- /srv/nginx/data/certs:/etc/nginx/certs:rw
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- proxy
networks:
proxy:
driver: bridge
For WordPress
services:
db:
container_name: $DB_CONTAINER
image: mysql:5.7
restart: always
volumes:
- ./db_data:/var/lib/mysql
environment:
#MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
MYSQL_DATABASE: $DB_NAME
MYSQL_USER: $DB_USER
MYSQL_PASSWORD: $DB_PASSWORD
wp:
container_name: $WP_CONTAINER
image: wordpress:latest
depends_on:
- db
expose:
- 80
restart: always
extra_hosts:
- "my-domain-name.com:192.168.80.2"
volumes:
#- ./wp-config.php:/var/www/html/wp-config.php:rw
- ./wp-content:/var/www/html/wp-content:rw
environment:
WORDPRESS_DB_HOST: $DB_CONTAINER
WORDPRESS_DB_NAME: $DB_NAME
WORDPRESS_DB_USER: $DB_USER
WORDPRESS_DB_PASSWORD: $DB_PASSWORD
WORDPRESS_TABLE_PREFIX: $WP_TABLE_PREFIX
VIRTUAL_HOST: $VIRTUAL_HOST
VIRTUAL_PORT: $VIRTUAL_PORT
LETSENCRYPT_HOST: $LETSENCRYPT_HOST
LETSENCRYPT_EMAIL: $LETSENCRYPT_EMAIL
WORDPRESS_CONFIG_EXTRA: |
define('ALTERNATE_WP_CRON', true);
networks:
default:
external:
name: nginx_proxy
This was so simple I've been kicking myself ever since I figured out what was wrong.
In the WP stack docker compose file this line was correct, but missing the 'www'.
- "www.my-domain-name.com:192.168.80.2"
In my WordPress setup the site URL included the www. So I was right to point the domain name to the IP of the Nginx container, but not including the full URL as specified in WP was causing the issue.
For anybody experiencing WP Site Health issues when using Docker, Nginx the solution is to use the "extra_hosts" directive in the wordpress container setup and point the IP of the Nginx container to the WordPress site URL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With