Running Discourse with Caddy Server

(Rafael dos Santos Silva) #1

:warning: This haven’t been tested yet, use at your own risk :warning:

Hello guys, I was moving stuff around in my test instance and got Discourse running with Caddy Server.

Cool stuff about Caddy:


  • Not as battle tested as apache, nginx and cia.

How To

Preparing Discourse

First, you need to apply this changes to your app.yml:

  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
  - "templates/web.socketed.template.yml" # <<<----- THIS IS NEW

## Let this two commented out
#  - "templates/web.ssl.template.yml"
#  - "templates/web.letsencrypt.ssl.template.yml"

## Let this two commented out 
#  - "8080:80"   # http
#  - "443:443" # https

  ## This should be commented out too

Preparing Caddy

In the spirit of Discourse, let’s put Caddy in a Docker image too :whale2:

First prepare with:

mkdir /var/caddy
nano /var/caddy/Caddyfile

Add the following to the Caddyfile # your domain here

proxy / unix:/sock/nginx.http.sock {

Save and exit.

Let’s test

Now you need to rebuild Discourse:

./launcher rebuild app

And then run Caddy:

docker run -d \
    -v /var/caddy/Caddyfile:/etc/Caddyfile \
    -v /var/caddy:/root/.caddy \
    -v /var/discourse/shared/standalone:/sock \
    -p 80:80 -p 443:443 \
    -p 80:80/udp -p 443:443/udp \
    --restart=always \
    --name caddy \
    --entrypoint "/usr/bin/caddy" \
    abiosoft/caddy -quic -email -agree --conf /etc/Caddyfile --log stdout

After all, your forum should be avaliable at your domain, using SSL + HTTP2 + QUIC. You can’t more hipster than that.

Where to host static site alongside Discourse Installation?
Can't login, reset password or create new account!
How can I install discourse as with Easyengine, Letsencrypt, Wordpress all together?
(Matt) #2

I run Caddy’s Discourse forums with this Caddyfile and no container:

timeouts off
proxy / localhost:8080 {

I just set up Discourse (with one easy tweak) and ran Caddy on the host machine.

^ This setup has been tested, and I can confirm it has been running with no glitches for months.

(Matthew Fay) #3

I like how you’ve proxied to the socket and left the ports unexposed.

Neat little guide that one can use as a guideline to easily incorporate their Discourse installation to an existing Caddy proxy, too. Cheers!

(RoldanLT) #4

But using nginx, as I can see now.

(Rafael dos Santos Silva) #5

Well, I have more than 1 Discourse install with Caddy in the front, but I didn’t bother to replace the server header and it still shows nginx. Can be the same. Or they are just using the simple Discourse install and have no need to run a reverse proxy at all in the front.

(Jay Pfaffman) #6

My Discourse sites behind Caddy show nginx as the server too. I guess that transparent setting might make Caddy, uh, transparent.

(Matt) #7

That might be a bug from a recent change, it didn’t used to do that. :thinking:

(honggian) #8

Dear @Falco

Thank you so much for your posting.

I would like to install discourse using caddy condition, but I was confused with your docker command.

I never heard about the caddy, so I follow the digital ocean document

My question is, in the current server situation, Should I change the path
from etc/Caddyfile to /etc/caddy/Caddyfile?

docker run -d \
    -v /var/caddy/Caddyfile:/etc/Caddyfile \
    -v /var/caddy:/root/.caddy \
    -v /var/discourse/shared/standalone:/sock \
    -p 80:80 -p 443:443 \
    -p 80:80/udp -p 443:443/udp \
    --restart=always \
    --name caddy \
    --entrypoint "/usr/local/bin/caddy" \
    abiosoft/caddy -quic -email -agree --conf /etc/Caddyfile --log stdout