无法使用SSL终止的负载均衡器登录到WordPress管理员

时间:2017-04-02 作者:jtl

使用HAProxy(版本1.7.2)前端运行Wordpress 4.7.3,使用PHP 5.6后端运行Pache 2.4.10。

这一切都在Debian 8.7

X-Forwarded-ForX-Forwarded-Proto 由HAProxy正确设置。

我遇到的问题是,当我在HAProxy前端终止SSL(运行http模式)并登录Wordpress Admin时,我会收到错误

抱歉,不允许您访问此页面。

我试了一下here 但他们没有解决这个问题。

在我的wp-config.php 我有

define(\'FORCE_SSL_ADMIN\', true);
// in some setups HTTP_X_FORWARDED_PROTO might contain
// a comma-separated list e.g. http,https
// so check for https existence
if (strpos($_SERVER[\'HTTP_X_FORWARDED_PROTO\'], \'https\') !== false)
       $_SERVER[\'HTTPS\']=\'on\';
我尝试了Wordpress的干净安装(正在导入早期Wordpress的客户端进行春季清理,但这也没有解决问题)。

1 个回复
SO网友:jtl

我刚刚解决了这个问题。

您需要在之前添加HTTPS/SSL设置require_once(ABSPATH . \'wp-settings.php\'); 在您的wp-config.php

因此wp-config.php 应该是这样的。

define( \'FORCE_SSL_ADMIN\', true );

// in some setups HTTP_X_FORWARDED_PROTO might contain
// a comma-separated list e.g. http,https
// so check for https existence
if( false !== strpos( $_SERVER[\'HTTP_X_FORWARDED_PROTO\'], \'https\' ) ) {
    $_SERVER[\'HTTPS\'] = \'on\';
}

/** Sets up WordPress vars and included files. */
require_once( ABSPATH . \'wp-settings.php\' );