Skip to content

Instantly share code, notes, and snippets.

@stefanpejcic
Created July 10, 2025 16:03
Show Gist options
  • Save stefanpejcic/13ec249383698bb93309e18314ed7a9c to your computer and use it in GitHub Desktop.
Save stefanpejcic/13ec249383698bb93309e18314ed7a9c to your computer and use it in GitHub Desktop.
WordPress Must-use plugin for HTTPS behind Varnish Proxy
<?php
/**
* Plugin Name: HTTPS for wp-admin
* Description: Forces SSL for wp-admin via X-Forwarded-Proto.
*
* https://wpxss.com/wp-config-php/how-to-set-up-wordpress-behind-a-secure-reverse-proxy-using-nginx/
*/
add_action('muplugins_loaded', function () {
if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
$_SERVER['HTTPS'] = 'on';
}
if ( ! defined('FORCE_SSL_ADMIN') ) {
define('FORCE_SSL_ADMIN', true);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment