WordPress的使用Docker的Nginx:未加载静态文件 [英] Wordpress & Nginx with Docker: Static files not loaded

查看:288
本文介绍了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 to nginx upstream name. The above solution overwrites the default setting.

这篇关于WordPress的使用Docker的Nginx:未加载静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆