hi folks.
I’ve started using caddy as a replacement for nginx on a few projects, and broadly speaking, I like it.
It handles SSL setup nicely, it exposes lots of useful metrics for monitoring, and there isn’t the split between nginx and nginx plus when looking for documentation or tutorials.
Is anyone else using it for their config? If so, I’d find it useful to compare notes on getting it set up, as it’s well documented, and I find the config files really nice and readable.
I had never even heard of caddy until now. It looks really interesting.
Thanks for sharing! I’ll have to add that to my list of “things to try”.
(And to answer your question, you could probably guess that I’m not currently using it and don’t have anything to share.)
OK, I wrote up a short post about my experiences using with some sample django configs for common setups.
If you use Whitenoise and host your uploaded media on object storage this is all you need:
{
cert_issuer acme
email my@emailaddress.com
}
my.website {
reverse_proxy localhost:8000
}
As you can see, it’s pretty short, and this is a working production ready setup.
Running a slightly more complex version where you serve static files locally (i.e. serving the output of collectstatic from local directory called staticfiles
at /static
as well as media files from media
at /media/
) on the same computer isn’t much more code.
Here it is:
my.awesomesite {
handle_path /static/* {
root * ./staticfiles/
file_server
}
handle_path /media/* {
root * ./media/
file_server
}
reverse_proxy 127.0.0.1:8000
}
That’s it!
More in this post below, explaining some of this in more detail.
https://rtl.chrisadams.me.uk/2023/01/til-using-caddy-with-django-apps-instead-of-nginx/
4 Likes
This is note to any one coming to this post.
The upgrade to Django 4.0 added a wrinkle to this, which I’ve blocked at the link below.
TLDR: if you are behind Caddy, and you know you will be serving Django behind it, then you can add the following one liner for POST requests to work if you were using a version of Django older than 4.0, and have recently upgraded.
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
https://rtl.chrisadams.me.uk/2024/05/til-keeping-your-hair-when-upgrading-django-3-2-behind-a-caddy-server/
2 Likes