Skip to content

Instantly share code, notes, and snippets.

@lopezjurip
Last active April 17, 2024 00:03
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lopezjurip/5314252970cc94970058320ac78f490a to your computer and use it in GitHub Desktop.
Save lopezjurip/5314252970cc94970058320ac78f490a to your computer and use it in GitHub Desktop.
Fix Too Many Redirect error using Caddy + Cloudflare

On Cloudflare, go to Crypto -> SSL and set it to Full or Full(strict)

www.mysite.com, mysite.com {
proxy / webapp:3000 {
proxy_header Host {host}
proxy_header X-Real-IP {remote}
proxy_header X-Forwarded-Proto {scheme}
}
gzip
tls your@email.com
}
proxy:
image: zzrot/alpine-caddy
restart: always
ports:
- 80:80
- 443:443
links:
- webapp
volumes:
- ./Caddyfile:/etc/Caddyfile
- ./.caddy:/root/.caddy
webapp:
build: .
restart: always
environment:
- NODE_ENV=production
FROM node:6-onbuild
EXPOSE 3000
/* eslint no-console:0 strict:0 */
'use strict';
const express = require('express');
const path = require('path');
const morgan = require('morgan');
const app = express();
app.use(morgan('combined'));
// serve static assets normally
app.use(express.static(`${__dirname}/public`));
app.get('*', (request, response) => {
response.sendFile(path.resolve(__dirname, 'public', 'index.html'));
});
app.listen(3000, err => {
if (err) console.error(err);
console.log('Web app listening on port 3000');
});
@Keda87
Copy link

Keda87 commented Dec 26, 2021

thanks!! my issue fixed after change my SSL settings in cloudflare into Full(strict)

Do you know, why this happened?

@zalo
Copy link

zalo commented Oct 20, 2023

I just want to +1 that changing my SSL settings at https://dash.cloudflare.com/{user-id}/{domain}/ssl-tls to Full fixed the "Too many redirects" issue immediately!

Thank you for putting this guide up! I assume it's due to Let's Encrypt and Caddy's own SSL certificates.

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