brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: FORCE_SSL_ADMIN keeps WordPress logins on HTTPS, mind the proxy

WordPress
~/tips/tip-wordpress-force-ssl-admin-proxy

define( 'FORCE_SSL_ADMIN', true );

Forces the login page and admin onto HTTPS and explains the redirect loop behind a proxy.

This constant makes WordPress send every login and admin request over HTTPS, so passwords and cookies never travel in plain text.

define( 'FORCE_SSL_ADMIN', true );

With it on, wp-login.php and /wp-admin/ redirect to HTTPS, and the login cookie is set as secure. Worth knowing: when you don’t define it, current WordPress sets it to true by itself if your siteurl starts with https. So on a site that is fully HTTPS, defining it mostly makes the intent visible in the config.

The catch is a reverse proxy that handles TLS, like nginx, Caddy or Traefik in front of a WordPress container. WordPress then sees plain HTTP from the proxy, thinks the request is insecure, and redirects again. That is an endless loop. WordPress decides via $_SERVER['HTTPS'], so the documented fix tells it about the header the proxy sends:

if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && strpos( $_SERVER['HTTP_X_FORWARDED_PROTO'], 'https' ) !== false ) {
    $_SERVER['HTTPS'] = 'on';
}

I’d put it above the “stop editing” line. Only do this when your proxy really sets that header and nobody can reach WordPress around the proxy, because otherwise a client could send the header itself.

Further reading: HTTPS for WordPress, wp-config: Require SSL for admin and logins

More WordPress tips wp user application-password create anna backup-script --porcelain define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size All WordPress tips (85) All topics

Link