Sample set up with django and caddy

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/

1 Like