Caddy and Django

I’m trying to get Caddy to use my Django project. Even finding documentation for Caddy with Python is difficult to find.
I haven’t tried anything so far

Try the example: examples/django at master · caddyserver/examples · GitHub - this repo is even linked to by the Caddy docs.

Wow it Matt himself. Seen part of your video in Caddy. I really enjoyed your presentation skills. You were a great speaker!

But yeah, I’m not sure how to do steps 3 and 4 on the example and I’m not sure what project.wsgi is.

1 Like

Step 3 is proxying from Caddy to gunicorn. From the gunicorn docs:

-b BIND, --bind=BIND - Specify a server socket to bind.

So we know based on the example gunicorn command that it’s listening on port :8000 on the address 127.0.0.1. We’ll need to proxy to it - check out the usage of the proxy directive in the example Caddyfile at examples/django/Caddyfile at master · caddyserver/examples · GitHub.

If your setup is more complex than that you’ll need to modify that appropriately, as well as the gunicorn launch.

project.wsgi is Django’s default output; check out the docs here: How to deploy with WSGI | Django documentation | Django

There’s even some gunicorn-specific deployment documentation for Django here: How to use Django with Gunicorn | Django documentation | Django

If you follow that, the rest is simply putting Caddy in front and proxying everything back.

I have to admit I’m confused by step 4 as well. I’d read “statics and medias” as images, CSS, JS, video, etc; with all requests going to gunicorn, though, I’d expect it to be handled there (it’s not like Caddy will serve anything on this site label anyway, with the proxy / sending everything upstream).

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.