“Too many redirects” when using WordPress as container

Aron Schüler Published


WordPress in Docker can cause quite some headache. Especially the reverse proxy, which we need to pass through traffic from host to container. I struggled with a “Too Many Redirects” error, which can come from some different sources. Let’s investigate which of those it will be for you!

Option 1: Cloudflare

If you are running your webserver behind Cloudflare, you could be suffering from a wrong SSL/TLS setting.

For me, the setting has to look like the following, with encryption mode set to Full:

<img loading=“lazy” width=“1024” height=“579” src=“https://lakur.tech/wp-content/uploads/2021/12/grafik-2-1024x579.png” alt=“Fix “Too many redirects” when using WordPress as container with Cloudflare SSL/TLS” class=“wp-image-159” srcset=“https://lakur.tech/wp-content/uploads/2021/12/grafik-2-1024x579.png 1024w, https://lakur.tech/wp-content/uploads/2021/12/grafik-2-300x170.png 300w, https://lakur.tech/wp-content/uploads/2021/12/grafik-2-768x434.png 768w, https://lakur.tech/wp-content/uploads/2021/12/grafik-2.png 1049w” sizes=“(max-width: 1024px) 100vw, 1024px” />

Fix “Too many redirects” when using WordPress as container with Cloudflare SSL/TLS

You could also experience bad cache, served by Cloudflare. To rule out this, we have to go to Caching on the left hand side menu and select Configuration there. Now you should see a blue purge everything button, which you want to use.

If this didn’t help or apply, we shall proceed to option 2.

Option 2: WordPress not configured for reverse proxy

The reverse proxy requires a special configuration of WordPress. It has to be aware of the traffics origin, which is not the container but the host, so it does not try to redirect incoming HTTP requests to HTTPS. This can be done by adding the following lines to your wp-config.php, which make WordPress aware of the reverse proxy:

  // If we're behind a proxy server and using HTTPS, we need to alert WordPress of that fact
  if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
          $_SERVER['HTTPS'] = 'on';
  }

This code is also documented at

Option 3: The obvious, cookies and cache.

If you’re still getting the errors, you should go ahead and try to access the website over your smartphone using cellular connection, not your wifi. If it is resolved by doing so, you can narrow the problem down to three options: It’s either your wifi, your browsers cache or cookies set by the website.

Your wifi would be bad and a too lengthy topic to cover here, but comment and I’ll might be able to help you out.

Your browsers cache can be easily deleted. On Chrome, you use the key combination Control + Shift + Delete, which brings up a menu where you want to select the last option, images and files in cache, and delete everythin. This will not log you out in your favorite social media, but force your browser to refetch every script and image. On Firefox, it is the same procedure, but the option is named Cache.

Cookies are also easy. For Chrome, that would require clicking the lock icon next to your url, selecting Cookies and then selecting and deleting every cookie in that list, just to be sure. On Firefox, you click the lock icon, select Delete cookies and website data and confirm the shown dialog.

Done, hopefully!

These options did the trick for me. More quick fixes and tutorials on WordPress can be found under the WordPress tag! If your “Too many redirects” when using WordPress as container was not resolved by this, leave a comment and tell me what you tried. We might be able to solve this together. If it was resolved, I am happy I could help and I hope to see you in the next post!


Related Posts

Find posts on similar topics:


Support me via buymeacoffee

If I helped you solve a problem or you just like my content, consider supporting me by buying me a coffee.

Buy me a coffee

Comments