2022-12-05 13:39:27 +00:00
|
|
|
# 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
|
2022-12-05 13:39:27 +00:00
|
|
|
all else.
|
|
|
|
|
2023-04-22 22:05:31 +00:00
|
|
|
To set up a Varnish cache, first you'll need to install Varnish.
|
2022-12-05 13:39:27 +00:00
|
|
|
|
|
|
|
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.
|
2022-12-05 13:39:27 +00:00
|
|
|
|
2023-04-22 22:05:31 +00:00
|
|
|
Copy the configuration file to the Varnish configuration directory:
|
2022-12-05 13:39:27 +00:00
|
|
|
|
|
|
|
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.
|
2022-12-05 13:39:27 +00:00
|
|
|
|
2023-04-22 22:05:31 +00:00
|
|
|
Then boot up Varnish, probably `systemctl start varnish` or `service varnish start`.
|
2022-12-05 13:39:27 +00:00
|
|
|
|
|
|
|
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.
|
2022-12-05 13:39:27 +00:00
|
|
|
|
2023-04-22 22:05:31 +00:00
|
|
|
Once that's out of the way, we can point our webserver at Varnish. This
|
2022-12-05 13:39:27 +00:00
|
|
|
|
2023-04-22 22:05:31 +00:00
|
|
|
=== "NGINX"
|
2022-12-05 13:39:27 +00:00
|
|
|
|
|
|
|
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.
|