akkoma/docs/docs/configuration/optimisation/varnish_cache.md

54 lines
1.6 KiB
Markdown
Raw Normal View History

# Using a Varnish Cache
Varnish is a layer that sits between your web server and your backend application -
2023-04-22 22:05:31 +00:00
it does something similar to NGINX caching, but tends to be optimized for speed over
all else.
2023-04-22 22:05:31 +00:00
To set up a Varnish cache, first you'll need to install Varnish.
This will vary by distribution, and since this is a rather advanced guide,
no copy-paste instructions are provided. It's probably in your distribution's
package manager, though. `apt-get install varnish` and so on.
2023-04-22 22:05:31 +00:00
Once you have Varnish installed, you'll need to configure it to work with Akkoma.
2023-04-22 22:05:31 +00:00
Copy the configuration file to the Varnish configuration directory:
cp installation/akkoma.vcl /etc/varnish/akkoma.vcl
2023-04-22 22:05:31 +00:00
You may want to check if Varnish added a `default.vcl` file to the same directory,
if so, you can just remove it without issue.
2023-04-22 22:05:31 +00:00
Then boot up Varnish, probably `systemctl start varnish` or `service varnish start`.
Now you should be able to `curl -D- localhost:6081` and see a bunch of
2023-04-22 22:05:31 +00:00
Akkoma JavaScript.
2023-04-22 22:05:31 +00:00
Once that's out of the way, we can point our webserver at Varnish. This
2023-04-22 22:05:31 +00:00
=== "NGINX"
upstream phoenix {
server 127.0.0.1:6081 max_fails=5 fail_timeout=60s;
}
=== "Caddy"
reverse_proxy 127.0.0.1:6081
Now hopefully it all works
If you get a HTTPS redirect loop, you may need to remove this part of the VCL
```vcl
if (std.port(server.ip) != 443) {
set req.http.X-Forwarded-Proto = "http";
set req.http.x-redir = "https://" + req.http.host + req.url;
return (synth(750, ""));
} else {
set req.http.X-Forwarded-Proto = "https";
}
```
2023-04-22 22:05:31 +00:00
This will allow your webserver alone to handle redirects.