Hi All,
I'm migrating a wordpress website to docker , I configured a docker-compose.yml with 2 services: wordpress and mysql.
We currently use a Docker Swarm cluster consisting of 2 nodes.
A manager node with Traefik as reverse proxy (with letsencrypt) and Portainer
and a worker node with the wordpress stack.
Traefik and Portainer dashboards work correctly in https.
I don't know where the problem may be, but once configured everything (source file, database, etc ...) if I configure the wordpress domain with "http" it works if I configure with "https" generates the error "ERR_TOO_MANY_REDIRECTS".
I set up the domain using the WP-CLI with the following commands:
wp search-replace 'http://www.domain.com/' '/' --skip-columns = guid --all-tables;
ant then
wp option update home 'https://www.domain.com';
wp option update siteurl 'https://www.domain.com';
or
wp option update home 'http://www.domain.com';
wp option update siteurl 'http://www.domain.com';
Here is a small diagram:

The infinite loop is probably caused by the reverse proxy:
https req => Traefik => http req => wordpress => redirect to https => repeat
Behind an SSL reverse proxy like Traefik you need to add these lines to the bottom of your wp-config.php:
/**
* Handle SSL reverse proxy
*/
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'];
}
Closing since this looks resolved
The infinite loop is probably caused by the reverse proxy:
https req => Traefik => http req => wordpress => redirect to https => repeatBehind an SSL reverse proxy like Traefik you need to add these lines to the bottom of your wp-config.php:
/** * Handle SSL reverse proxy */ 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']; }
The proposed addition to wp-config.php works fine. However, in order to get WP fully working, it should be added to the very top of the config file. Just to let people know who stumble upon this from now on.
The infinite loop is probably caused by the reverse proxy:
https req => Traefik => http req => wordpress => redirect to https => repeat
Behind an SSL reverse proxy like Traefik you need to add these lines to the bottom of your wp-config.php:/** * Handle SSL reverse proxy */ 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']; }The proposed addition to
wp-config.phpworks fine. However, in order to get WP fully working, it should be added to the very top of the config file. Just to let people know who stumble upon this from now on.
I've tried adding this to the top and bottom of my wp-config file but I'm still stuck with the redirect loop.
remove if ($_SERVER['HTTP_X_FORWARDED_PROTO']:
$_SERVER['HTTPS']='on';
OR
Traefik Adding X-Forwarded-Proto Headers
https://docs.traefik.io/middlewares/headers/
Example:
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik"
- "traefik.http.middlewares.my-container-behind-proxy.headers.customrequestheaders.X-Forwarded-Proto=https"
- "traefik.http.routers.my-container.entrypoints=web"
- "traefik.http.routers.my-container.rule=Host(www.domain.com)"
- "traefik.http.routers.my-container.service=my-container"
- "traefik.http.routers.my-container.middlewares=my-container-behind-proxy"
- "traefik.http.services.my-container.loadbalancer.server.port=80"
Most helpful comment
The infinite loop is probably caused by the reverse proxy:
https req => Traefik => http req => wordpress => redirect to https => repeat
Behind an SSL reverse proxy like Traefik you need to add these lines to the bottom of your wp-config.php: