I’m setting up a simple environment on docker with the following stack:
- nginx as load balance
- wordpress instance
- mysql
My simple docker compose file is the following:
nginx:
build: ../nginx
links:
- wordpress:wordpress
ports:
- "80:80"
- "443:443"
wordpress:
image: wordpress
ports:
- "8082:80"
links:
- mysqlwp:mysql
working_dir: /var/www/html
#volumes:
# - wp-content/:/var/www/html/wp-content
environment:
WORDPRESS_DB_HOST: mysql
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
mysqlwp:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
nginx is built from base image and configuration is the following:
upstream wploadbalance{
least_conn;
server wordpress;
}
server {
listen 80;
server_name my.site.com;
location / {
proxy_pass http://wploadbalance;
}
}
Now when I connect to my.site.com I’m correctly redirected to my the wordpress instance but static files are loaded from http://wploadbalance
which is not accessible.
For example in my browser console I see something like that:
GET
http://wploadbalance/wp-includes/js/wp-util.min.js?ver=4.4
net::ERR_NAME_NOT_RESOLVED
As wploadbalance
is not accessible from outside docker container there should by some way to say to wordpress that static files are serverd from my.site.com
. Does anyone know how to achieve this?
Solution:
Log in to the container:
docker exec -it "name_of_container" bash
Add the following lines to wp-config.php
define('WP_HOME', 'http://your_domain.com');
define('WP_SITEURL', 'http://your_domain.com');