How to set up WordPress behind a secure reverse proxy using NGINX

After getting your SSL-certificate and have enabled HTTPS redirection in NGINX, WordPress will not work due to mixed content (HTTP and HTTPS) – you won’t be able to login.

In order to fix this you first have to add this at the very start of your wp-config.php.

define('FORCE_SSL_ADMIN', true); if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
Code language: PHP (php)

Then in the end of the file add the following, replacing “website.com” with your own URL.

define('WP_HOME','https://website.com'); define('WP_SITEURL','https://website.com');
Code language: JavaScript (javascript)

Finally you have to add the following to your NGINX-config in the site’s location block on your reverse proxy.

proxy_set_header X-Forwarded-Proto https;

Now it should be working! You should probably also add the plugin Really Simple SSL for their mixed content fixer.