3

I'm trying to run wordpress on a docker based cloud. The setup is:

Wordpress Cloud Setup

There is a server running a mysql array, which serves a container with Wordpress Running on Nginx. The setup is copied from this dockerfile. The goal of this setup is to achieve a high throughput and be compatible with our cloud setup.

The wordpress container has a local ip, in the same subnet as the mysql array and Nginx reverse proxy, and a public port to run http (not https).

The reverse proxy is configured to run SSL for the wordpress container. Navigation works on both http and https, but when I try to log in the dashboard with HTTPS, I get this error:

You do not have sufficient permissions to access this page.

The only meaningful error I found happens when I log in on the dashboard, on HTTP:

[04-Nov-2014 23:16:13 UTC] PHP Notice: Undefined index: HTTP_X_FORWARDED_PROTO in /usr/share/nginx/www/wp-config.php on line 86

but the dashboard works correctly on http.

In Wordpress configuration file I had to add the line:

/* SSL Proxy */

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';

And I think this is the culprit. I found this tip in the official wordpress documentation, and without it HTTPS doesnt load the CSS, either logged or not logged. I think maybe I should modify this line to suit my configuration?

Either this, or the nginx reverse proxy configuration file, I have no idea.

The nginx configuration file in the wordpress + nginx container is quite standard, and it's copied from here.

Please help me :D

7
  • 1
    It seems your nginx proxy doesnt send the correct headers (or the nginx inside the WP container doesnt forward that header into PHP... ) Try debugging the output of the NGINX reverse proxy and then looking into what comes into the WP container
    – Gekkie
    Nov 6, 2014 at 9:38
  • how would you do that?
    – Mascarpone
    Nov 10, 2014 at 10:28
  • 1
    replace the various backends to a simple PHP script which dumps the headers ($_SERVER i.e.) and see what happens... It might be that one of you nginx-servers just messes up the headers?
    – Gekkie
    Nov 10, 2014 at 12:18
  • Can you paste the contents of the Nginx server configuration fastcgi_params?
    – ojrask
    Dec 19, 2014 at 11:58
  • where do I find them? I guess it was the default ones
    – Mascarpone
    Dec 21, 2014 at 12:25

2 Answers 2

6

I had some problem, I resolved in this way:

in my wp-config.php,

I added these lines:

if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) $_SERVER['HTTPS']='on';

BEFORE everything in the code.

Hope it helps!

3
  • if the line was put at the bottom of the config file, there will be a problem. this is what fixed the problem for me.
    – pdwalker
    Jan 11, 2017 at 9:47
  • was struggling with this for hours, until putting it before everything in the code, that did the trick! thanks! Aug 20, 2017 at 23:36
  • yes, the placement of the snippet was crucial! Thanks :)
    – Giordano
    Nov 4, 2017 at 22:41
0

I have used this block of code in wp-config.php for nginx reverse proxy => Apache

// When behind reverse proxy
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
    $_SERVER['HTTPS']= 'on';
}

if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
    $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
}
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 12, 2022 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .