简体   繁体   English

无法通过 HTTPS 访问 WordPress docker 容器的静态文件

[英]Cannot access static files of WordPress docker container over HTTPS

I am trying to create a WordPress container over HTTPS, I have Apache running on the VPS and using it as a proxy to route requests to WordPress container.我正在尝试通过 HTTPS 创建一个 WordPress 容器,我在 VPS 上运行 Apache 并将其用作代理将请求路由到 WordPress 容器。

I've managed to access the container to load WordPress Installation page over HTTPS but CSS/JS files won't load because they are requested over HTTP I don't know why the redirect is not working with these files, I did other websites like this.我已经设法访问容器以通过 HTTPS 加载 WordPress 安装页面,但是 CSS/JS 文件无法加载,因为它们是通过 HTTP 请求的我不知道为什么重定向不适用于这些文件,我做了其他网站,如这个。

Here is a print of the output这是输出的打印

If I access the files on ' http://example.com/wp-admin/css/install.min.css?ver=5.2.2 ' the redirect works fine (print of the css file over HTTPS after accesing the link above)如果我访问“ http://example.com/wp-admin/css/install.min.css?ver=5.2.2 ”上的文件,重定向工作正常(访问上面的链接后通过 HTTPS 打印 css 文件)

This is the redirect for 80 to 443 on the domain.这是域上 80 到 443 的重定向。

<VirtualHost *:80>
    ServerName example.com
    ServerAdmin admin@example.com
    Redirect permanent / https://example.com/
</VirtualHost>

Here is the proxy on 443:这是 443 上的代理:

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ServerName example.com
        ProxyPreserveHost On

        ProxyPass / http://172.20.0.100/ 
        ProxyPassReverse / http://172.20.0.100/


        SSLEngine on

        SSLCertificateFile /fullchain.pem
        SSLCertificateKeyFile /privkey.pem
    </VirtualHost>
</IfModule>

WordPress container listens only on port 80 WordPress 容器仅侦听端口 80

Here is the docker-compose file:这是 docker-compose 文件:

version: '3'

services:
  wpdb:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
        MYSQL_ROOT_PASSWORD: pass
        MYSQL_DATABASE: wordpress
        MYSQL_USER: wordpres_admin
        MYSQL_PASSWORD: pass

  wordpress:
    depends_on:
     - wpdb
    image: wordpress:latest

    networks:
      default:
        ipv4_address: 172.20.0.100
    restart: always
    environment:
        WORDPRESS_DB_HOST: wpdb:3306
        WORDPRESS_DB_USER: wordpres_admin
        WORDPRESS_DB_PASSWORD: pass
volumes:
    db_data: {}

networks:
 default:
   external:
     name: router_default

How can i solve this problem?我怎么解决这个问题?

I found the solution, looks like WP is already configured to be used through a proxy with SSL and there is no need to change anything in the WP container or WP settings, all that needs to be done is to rewrite the header of the request with :我找到了解决方案,看起来 WP 已经配置为通过带有 SSL 的代理使用,并且无需更改 WP 容器或 WP 设置中的任何内容,所有需要做的就是重写请求的标头:

RequestHeader set X-Forwarded-Proto "https"

The updated proxy config looks like this:更新后的代理配置如下所示:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName example.com

    <IfModule headers_module>
        RequestHeader set X-Forwarded-Proto "https"
    </IfModule>

    ProxyPreserveHost On

    ProxyPass / http://172.20.0.100/ 
    ProxyPassReverse / http://172.20.0.100/


    SSLEngine on

    SSLCertificateFile /fullchain.pem
    SSLCertificateKeyFile /privkey.pem
</VirtualHost>

For more info: https://wordpress.org/support/article/administration-over-ssl/#using-a-reverse-proxy and https://webmasters.stackexchange.com/questions/97005/setting-x-forwarded-proto-under-apache-2-4欲了解更多信息: https : //wordpress.org/support/article/administration-over-ssl/#using-a-reverse-proxyhttps://webmasters.stackexchange.com/questions/97005/setting-x-forwarded -proto-under-apache-2-4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM