Reverse Proxying WordPress

CaddyReverse ProxyWordPress

WordPress is annoying to reverse proxy. I won’t get into the details of why but instead just provide a quick fix. Open up your wp-config.php and place this block of code directly after the opening PHP tag:

<?php
$https = true; // Set to false if not using HTTPS.
$_SERVER['SERVER_PORT'] = $https ? 443 : 80;
// NOTE: My reverse proxy, Caddy, supplies the SERVER_NAME key/value 
// within the global $_SERVER associative array. If this is not the 
// case for you put your desired hostname here. For example, 
// `www.example.com`.
$url = ($https ? 'https' : 'http') . '://' . $_SERVER['SERVER_NAME'];
define('FORCE_SSL_ADMIN', $https);
define('WP_HOME', $url);
define('WP_SITEURL', $url);
// Rest of wp-config.php below...

I reverse proxy several hostnames/domains to the same WordPress instance which this wp-config.php supports. Good luck out there.

Next
A Minimal Backup Script

Prev
CI/CD! Who Needs ‘Em?