WordPress的使用Docker的Nginx:未加载静态文件
我正在使用Docker服务我的简单WordPress网站. Nginx容器和wordpress容器.简单设置:
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;
}
}
问题:未加载静态文件(css,js和图像).
Problem: Static files (css, js and images) are not loaded.
浏览器控制台的输出显示404:
The output from the browser console shows a 404:
http://wordpress_english/wp-content/themes/twentyfifteen/genericons/genericons.css?ver=3.2
很容易发现问题:浏览器在wordpress_english(nginx上游名称)而不是my_domain.com
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
如何解决此问题?
这不是nginx
问题,而是WordPress问题.
This is not a nginx
problem, but a WordPress problem.
解决方案:
在wp-config.php
中,添加以下两行:
define('WP_HOME','http://my_domain.com');
define('WP_SITEURL','http://my_domain.com');
在安装WordPress期间,WordPress会自动将
WP_HOME
设置为nginx
上游名称.上述解决方案将覆盖默认设置.
During the WordPress installation, WordPress automatically sets
WP_HOME
tonginx
upstream name. The above solution overwrites the default setting.