Skip to content

Instantly share code, notes, and snippets.

@aleksandar-babic
Created June 20, 2018 09:20
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save aleksandar-babic/0cdd3244f4bf6b13dbed68de96ba4ab1 to your computer and use it in GitHub Desktop.
Save aleksandar-babic/0cdd3244f4bf6b13dbed68de96ba4ab1 to your computer and use it in GitHub Desktop.
Wordpress behind NGINX reverse proxy
location /blog/ {
#auth_basic "Restricted";
#auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass https://test-blog.bitstarz.com/;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
}
// Proxy fix
define( 'WP_SITEURL', '/blog' );
define( 'WP_HOME', '/blog' );
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')
$_SERVER['HTTPS'] = 'on';
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
}
$_SERVER['REQUEST_URI'] = "/blog".$_SERVER['REQUEST_URI'];
@nguyenkiidu
Copy link

thank you!

@isaac-lee-mort
Copy link

Thank you! I've been banging my head against my desk for a while to fix this!

As I wasn't using a subdirectory, I only need this bit in my wp-config.php file:

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

if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
    $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
}

@itsfadnis
Copy link

Thank you! Life saver.

@LaserKaspar
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment