4

Running Wordpress 4.7.3 with a HAProxy (version 1.7.2) frontend and Apache 2.4.10 with PHP 5.6 backend.

This is all under Debian 8.7 as well.

X-Forwarded-For and X-Forwarded-Proto are set correctly by HAProxy.

The issue I'm having is when I have SSL terminated on the HAProxy frontend (running http mode) and login to Wordpress Admin I get the error

Sorry, you are not allowed to access this page.

I tried the steps from here but they didn't fix the issue.

At the bottom of my wp-config.php I have

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';

I tried a clean install of Wordpress (was importing a clients side of an earlier Wordpress for spring cleaning, but that didn't fix the issue either).

1 Answer 1

7

I just figured out the issue.

You need to add the HTTPS/SSL settings before require_once(ABSPATH . 'wp-settings.php'); in your wp-config.php

So the relevant part of your wp-config.php should look like this.

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' );
2
  • 1
    Adding the the code above the require_once( ABSPATH . 'wp-settings.php' ); is very important or else it will not work Dec 5, 2017 at 19:27
  • thanks for sharing, this should be added to the official documentation: codex.wordpress.org/…
    – baptx
    Dec 21, 2017 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.