# Varnish config for discourse

**URL:** https://meta.discourse.org/t/varnish-config-for-discourse/68575
**Category:** Self-hosting
**Tags:** hosting
**Created:** [August 23, 2017, 1:27am UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575 "2017-08-23T01:27:50Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![Quintin\_Par](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/quintin_par/32/120500_2.png) [@Quintin\_Par](https://meta.discourse.org/u/Quintin_Par)
#### Post date: [August 23, 2017, 1:27am UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/1 "2017-08-23T01:27:50Z")

</div>

Is there an official config for discourse that I can use?

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [August 23, 2017, 1:33am UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/2 "2017-08-23T01:33:05Z")

</div>

There is not an official Varnish config for Discourse.

---

<div class="post-metadata">

### Author: ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)
#### Post date: [August 23, 2017, 3:03am UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/3 "2017-08-23T03:03:00Z")

</div>

Not official, but there have been some stabs at it before.

> [@Use HAProxy and Varnish with Discourse](https://meta.discourse.org/t/adventures-in-haproxy-and-varnish-with-discourse-because-i-hate-myself/27782/):
>
> Had some downtime this afternoon and without even really planning to ended up setting up haproxy in front of my web server, which hosts a bunch of stuff including Discourse. The configuration, surprisingly, wound up working without much hassle at all; I give up SPDY support because haproxy doesn’t support it, but I don’t think that’s going to have a whole lot of material effect. I wound up dragging a second unused server into the mix to work as the haproxy host, but I don’t think there’d be any…

---

<div class="post-metadata">

### Author: ![Quintin\_Par](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/quintin_par/32/120500_2.png) [@Quintin\_Par](https://meta.discourse.org/u/Quintin_Par)
#### Post date: [August 23, 2017, 1:36pm UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/4 "2017-08-23T13:36:49Z")

</div>

Thanks. A bit surprised there since Discourse has official support for Fastly and that means there should be a config the team uses.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [August 23, 2017, 3:25pm UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/6 "2017-08-23T15:25:43Z")

</div>

Fastly does standard origin pull, you don’t need to fuss with Varnish. We have already 2 howtos that cover this depending on your level of adventure/pain.

> [@Enable a CDN for your Discourse](https://meta.discourse.org/t/enable-a-cdn-for-your-discourse/14857):
>
> So you’d like to use a CDN to speed up worldwide access to common assets on your Discourse forum? You might want to go all-in and [Set up file and image uploads to S3](https://meta.discourse.org/t/setting-up-file-and-image-uploads-to-s3/7229) (see also [Configure an S3 compatible object storage provider for uploads](https://meta.discourse.org/t/configure-an-s3-compatible-object-storage-provider-for-uploads/148916)). If you want a CDN without the added complexity of S3 and having two CDNs, this is the guide for you. The CDN will reduce some load on your server by letting the CDN serve those assets so that the server doesn’t have to. It also can speed things up by deliver…

> [@Full site CDN acceleration for Discourse](https://meta.discourse.org/t/full-site-cdn-acceleration-for-discourse/21467):
>
> [Fastly](http://www.fastly.com/) , [CloudFlare](https://www.cloudflare.com) and a few other CDNs offer a mode where they accelerate dynamic content. In a nutshell you point your domain IP address at the CDN and the CDN will intelligently decide how to deal with the request. Static content can be easily served from cache Dynamic content can be routed to the site. This provides some advantages over only shipping static assets which is covered in [the CDN howto](https://meta.discourse.org/t/enable-a-cdn-for-your-discourse/14857). You can elect for “[shielding](http://www.fastly.com/products/origin-shield/)” that protects your site from traffic spikes. Dynamic cont…

[https://community.fastly.com/](https://community.fastly.com/) is configured using “full site CDN acceleration”

---

<div class="post-metadata">

### Author: ![Quintin\_Par](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/quintin_par/32/120500_2.png) [@Quintin\_Par](https://meta.discourse.org/u/Quintin_Par)
#### Post date: [August 23, 2017, 6:47pm UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/7 "2017-08-23T18:47:24Z")

</div>

Please correct me if I am wrong, but don’t you need to do invalidation when some one replies, update categories pages when new content is added etc. My understanding is that one needs to run the invalidation logic from the code to caching system. Therefore I thought Discourse should be having a varnish config file that’s probably deployed on Fastly.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [August 23, 2017, 6:51pm UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/8 "2017-08-23T18:51:04Z")

</div>

> [@Quintin\_Par](#):
>
> Please correct me if I am wrong, but don’t you need to do invalidation when some one replies, update categories pages when new content is added etc.

no not really, you only have to invalidate stuff you are caching.

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [August 23, 2017, 7:22pm UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/9 "2017-08-23T19:22:06Z")

</div>

> [@Quintin\_Par](#):
>
> but don’t you need to do invalidation when some one replies, update categories pages when new content is added etc. My understanding is that one needs to run the invalidation logic from the code to caching system

Discourse can only use a CDN for static assets, not for content.

---

<div class="post-metadata">

### Author: ![Quintin\_Par](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/quintin_par/32/120500_2.png) [@Quintin\_Par](https://meta.discourse.org/u/Quintin_Par)
#### Post date: [August 23, 2017, 7:51pm UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/10 "2017-08-23T19:51:25Z")

</div>

Ohh ooh. That’s a revelation. Huge bummer.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [August 23, 2017, 7:54pm UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/11 "2017-08-23T19:54:23Z")

</div>

I don’t think what @RGJ said is correct; you can visit our hosted Fastly community at [https://community.fastly.com/](https://community.fastly.com/) which goes entirely through Fastly, content and all.

---

<div class="post-metadata">

### Author: ![Quintin\_Par](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/quintin_par/32/120500_2.png) [@Quintin\_Par](https://meta.discourse.org/u/Quintin_Par)
#### Post date: [August 23, 2017, 7:57pm UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/14 "2017-08-23T19:57:46Z")

</div>

Thanks Jeff. Huge relief. Am I right in assuming that [https://community.fastly.com/](https://community.fastly.com/) ‘s varnish config is by them and not by the discourse community.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [August 23, 2017, 7:58pm UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/15 "2017-08-23T19:58:54Z")

</div>

We generally don’t recommend this config because it is quite complicated and does not get you much that a traditional (and far, _far_ simpler) CDN of static assets does not already deliver.

---

<div class="post-metadata">

### Author: ![Quintin\_Par](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/quintin_par/32/120500_2.png) [@Quintin\_Par](https://meta.discourse.org/u/Quintin_Par)
#### Post date: [August 23, 2017, 8:02pm UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/16 "2017-08-23T20:02:03Z")

</div>

CDN, in this case is not for performance but for high availability – I offload everything and my single server is hardly hit with more than 1 RPS (almost only the logged in people). In the eventuality that my server goes down(which often does), the read-only site is always up, even if the login and such functionality is limited.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [August 23, 2017, 8:18pm UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/17 "2017-08-23T20:18:19Z")

</div>

Hmmm … no … we never cache any dynamic content. Any caching we do is done in the app.

 ![image](https://global.discourse-cdn.com/meta/original/3X/7/9/79a52ba77c307b2f604f899bc1cbe2c4b5e986c5.png)

It is possible that a `vary` by `x-discourse-username` would allow us to cache for anon via headers. I never experimented with that implementation.

As it stands all dynamic requests like looking at this page hit the app.

---

<div class="post-metadata">

### Author: ![Quintin\_Par](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/quintin_par/32/120500_2.png) [@Quintin\_Par](https://meta.discourse.org/u/Quintin_Par)
#### Post date: [August 24, 2017, 12:30am UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/18 "2017-08-24T00:30:03Z")

</div>

Thank you for the clarification. I’ll also post this question on [https://community.fastly.com/](https://community.fastly.com/) in case they have something interesting.

---

<div class="post-metadata">

### Author: ![ryanerwin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryanerwin/32/94589_2.png) [@ryanerwin](https://meta.discourse.org/u/ryanerwin)
#### Post date: [April 20, 2018, 6:56am UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/19 "2018-04-20T06:56:13Z")

</div>

@Quintin_Par I saw you also posted over at Fastly…

Did you ever get this worked out? I’m surprised that even when configured as a “Full Site CDN” that [community.fastly.com](http://community.fastly.com) would go offline if their one server with discourse went offline.

I’ve got a setup right now with 2 descent sized web servers and 1 bigger data server. I’m also planning to setup one autoscaling instance at AWS which normally would only see ~5% of traffic, but when spikes come in would scale up additional servers…

My sites traffic comes in big spikes. Previously we had 500,000 users online at once, so that’s a lot of load to plan for…

Still having the site work via the CDN even if the server were down would just be fantastic, but my foremost concern is being able to handle big spikes.

## QUESTIONS:

- Did you end up going with Fastly? Full Site CDN?

- If you did, how do you feel about your experience with it? If not, what made you decide otherwise?

Thanks so much for any additional feedback you can make the time to offer.

---

<div class="post-metadata">

### Author: ![Quintin\_Par](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/quintin_par/32/120500_2.png) [@Quintin\_Par](https://meta.discourse.org/u/Quintin_Par)
#### Post date: [December 11, 2018, 4:45pm UTC](https://meta.discourse.org/t/varnish-config-for-discourse/68575/20 "2018-12-11T16:45:17Z")

</div>

Saw this late. Nope. No real CDN for Varnish/Fastly.
