使用 WordPress/apache proxypass 阻止/混合內容

使用 WordPress/apache proxypass 阻止/混合內容

我正在嘗試將 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'; }

相關內容