Caddy server configuration for Sanic?

Hi!

I’m wondering if someone has already tried to implement Sanic with Caddy?
The motivation behind using Caddy is the auto renewal of SSL certificates, which is a nice thing to have :slight_smile:

Unfortunately, I could not find any documentation on how to make Sanic run with Caddy in front. Does anyone have tried and succeeded in it?

Also, I’m running Sanic as a unix socket (app.run(sock='/var/www/fernand/uswgi.sock', debug=False, access_log=False)) if that helps.

Thank you for your help

I don’t what Caddy is and a certbot cronjob handles auto-renewal quite well already. But I have been thinking of writing a Sanic extension that directly runs cert upgrades within the Sanic server, perhaps avoiding the use of certbot CLI tool entirely.

Running Sanic behind another server usually degrades performance, unless the front is something super fast like Nginx, and configured to use keep-alive.

Maybe someone else has actual experience with Caddy?

Caddy is a proxy server, kind of like Nginx and HaProxy. It focused on an easy configuration file, and includes nice things like automatic SSL. If you have a few minutes, take a look to compare a Nginx configuration file and a Caddy one for the same purpose, and you’ll see :slight_smile:

But I agree, if a Sanic plugin exists to automate the SSL creation, then Caddy becomes useless in that. case (granted, if the performance notion is true)

Would you care to write documentation for it, similar to our Nginx deployment guide? It certainly seems an interesting development, and written in Go it can be fast enough (depending on quality of implementation more than the language choice).

You need unix='/tmp/sanic.sock' rather than sock= which is used when you already have a socket object.

Hi Tronic,

unfortunately I don’t have the time to write a documentation for this so I’m forced to decline.

As for your suggestion regarding unix vs socket, it, indeed, did the trick! Thank you!

1 Like

When you have a chance @Tronic ping me about this. I was thinking about adding this to Sanic Extensions.