5

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?

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.