How to run WordPress Blog behind Nginx Secure (https) Proxy

When I started this blog, I was asked, what was the most annoying thing I get while setup up a WordPress blog. I can’t really get SSL thing out of my head – yet. It was totally worth it.

When running a WordPress behind a proxy, it will give an error of unable to complete the request.

There are kinds of problem you will see:

  1. WordPress homepage is stuck in an endless loop.
  2. CSS/JS files are not loading.
  3. Transport error.

Solution:

Editing Nginx for WordPress behind Proxy

Add following proxy configuration in your Nginx

proxy_set_header X-Forwarded-Proto https;

Your nginx configuration should look more or less like:

    location / {
        try_files $uri @app;
    }
    location @app {
        proxy_set_header X-Forwarded-Proto https;
        proxy_pass http://127.0.0.1:8888;
        include .common/proxy.common;
    }

Config for SSL enabled WordPress behind Proxy

There is a possibility that you might need to add the following as well in wp-config.php file in some versions of WordPress.

if($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'){

    $_SERVER['HTTPS'] = 'on';
    $_SERVER['SERVER_PORT'] = 443;
}

Do you have wp-config.php inside Docker?

If your wp-config.php file is under Docker, then you can use docker cp command to copy/copy back file.

#Copy from docker container
docker cp project_wordpress_1:/var/www/html/wp-config.php .

#Copy to docker container
docker cp wp-config.php project_wordpress_1:/var/www/html/wp-config.php
How to run WordPress Blog behind Nginx Secure (https) Proxy

5 thoughts on “How to run WordPress Blog behind Nginx Secure (https) Proxy

  1. Everyone nowdays want a stateless machine but truth is, it is impossible! You can have virtual machines but that just about it.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top