我正在尝试设置一个 apache 反向代理到特定端口(8001),该端口链接到一个 wordpress docker 容器:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9592d33ed6c1 wordpress:5.5.0-php7.3-apache "docker-entrypoint..." 23 seconds ago Up 21 seconds 0.0.0.0:8001->80/tcp martynbiz_wordpress_1
7c0d046560d6 mysql:5.7 "docker-entrypoint..." 25 seconds ago Up 23 seconds 3306/tcp, 33060/tcp martynbiz_db_1
以下是我的 apache 配置文件:
/etc/apache2/sites-available/martynbiz.conf
<Virtualhost *:80>
ServerName www.martyn.biz
ServerAlias martyn.biz
ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes NoDecode
SSLProxyEngine On
SSLProxyCheckPeerCN on
SSLProxyCheckPeerExpire on
<Proxy http://localhost:8001/*>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8001/ nocanon
ProxyPassReverse / http://localhost:8001/
#RewriteEngine on
#RewriteCond %{SERVER_NAME} =martyn.biz
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.martyn.biz [OR]
RewriteCond %{SERVER_NAME} =martyn.biz
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</Virtualhost>
/etc/apache2/sites-available/martynbiz-le-ssl.conf
<IfModule mod_ssl.c>
<Virtualhost *:443>
ServerName www.martyn.biz
ServerAlias martyn.biz
ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes NoDecode
SSLProxyEngine On
SSLProxyCheckPeerCN on
SSLProxyCheckPeerExpire on
<Proxy http://localhost:8001/*>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8001/ nocanon
ProxyPassReverse / http://localhost:8001/
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/martyn.biz/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/martyn.biz/privkey.pem
</Virtualhost>
</IfModule>
我的证书似乎有效,反向代理正在将容器与域名链接起来。但是,我收到被阻止的混合内容,因此样式表等不会显示。如果我从配置文件中删除所有 SSL 内容,并使用 HTTP,则一切看起来都正常。我以前在设置 SSL 证书时从未遇到过这个问题 - 但过去我没有使用反向代理。我怀疑问题出在那,并且 apache 中 HTTP/HTTPS 配置错误?
答案1
通过在 wp-config.php 的最顶部(<?php 之后)添加以下内容来修复
if ( (!empty( $_SERVER['HTTP_X_FORWARDED_HOST'])) || (!empty( $_SERVER['HTTP_X_FORWARDED_FOR'])) ) { $_SERVER['HTTPS'] = 'on'; }