简体   繁体   中英

Changing Wordpress http to https behind a Load Balancer with ProxyPass

I run a Wordpress behind a other (main) webserver. The main Server does have a rule to redirect all requests to /wpa to the Wordpress Server with a ProxyPass

ProxyPass /wpa/ http://vm.example.com/wpa/
ProxyPassReverse /wpa/ http://vm.example.com/wpa/

Wordpress itself comes with this .htaccess file at the Wordpress root:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wpa/

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wpa/index.php [L]
</IfModule>

Everything is working fine with http. But I want to switch to https and this is a problem. The SSL termination is done at a Load Balancer.

The thing is, that all traffic behind the Load Balancer is non-ssl. If I change the Wordpress homeurl and siteurl from http to https, I get a redirect error (loop).

I tried to use a rule like this at the main server:

RewriteCond %{HTTPS} !=on
RewriteRule ^/wpa/(.*)$ https://www.example.com/wpa/$1 [L,R=301]

Still get a redirect error. I tried to check RewriteLog but I failed finding the right information.

Does anyone have a clue how to fix this?

  1. Use below code in wp-config.php,

define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS']='on';

  1. Check you .htaccess file, It should be clean.
  2. Re-save the permalink.
  3. If using CDN, Enable 443 port.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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