4

I'm using Docker to serve my simple WordPress website. A nginx container and a wordpress container. Simple setup:

upstream wordpress_english {
  server wordpress_en:80;
}

server {
  listen 80;
  server_name my_domain.com www.my_domain.com;

  location / {
        proxy_pass http://wordpress_english;
    }
}

Problem: Static files (css, js and images) are not loaded.

The output from the browser console shows a 404:

http://wordpress_english/wp-content/themes/twentyfifteen/genericons/genericons.css?ver=3.2

Its easy to spot the problem: The browser looks for the static files at wordpress_english (the nginx upstream name), instead of my_domain.com

How can I fix this problem?

Vingtoft
  • 13,368
  • 23
  • 86
  • 135

2 Answers2

4

This is not a nginx problem, but a WordPress problem.

Solution:

In wp-config.php, add the following two lines:

define('WP_HOME','http://my_domain.com');
define('WP_SITEURL','http://my_domain.com');

During the WordPress installation, WordPress automatically sets WP_HOME to nginx upstream name. The above solution overwrites the default setting.

Phoenix
  • 3,996
  • 4
  • 29
  • 40
Vingtoft
  • 13,368
  • 23
  • 86
  • 135
0

Seems to be an issue in your nginx config file.

When declaring your server my_domain you provide location / with proxy_pass wordpress_english. I don't know a lot on nginx, but I don't see any declaration of path in your server my_domain and is root is linked to wordpress_english. Seems normal that he is looking for files in wordpress_english and not in you server. (In fact, I guess he is looking in your server but your server tells to look in wordpress).

Not sure about it cause I don't know well nginx and proxy_pass functions.

Titouan Freville
  • 489
  • 4
  • 13