Description
OpenBSD has, by default, in basesystem, since 5.7:
-
a webserver, named httpd,
-
un server relay, named relayd
-
Website: https://bsd.plumbing/
-
OpenBSD: 6.6, 6.7
httpd is not able to manage delivery about cache static content.
So we pass the relay to the relayd server which is able to do it; so, it does in the global manner, not-domain specific.
Configuration
We need to modify the httpd and relayd configuration, i.e.:
- relayd will receive all traffic on web port and redirects to localhost on corresponding ports. Off course, il possible to act on both IPv4 and IPv6 protocols.
- httpd will query only the localhost on the dedicated ports.
Do not forget to restart both daemons after modyfing the configuration.
relayd
- File configuration is:
/etc/relayd.conf
In the contexte of the http
protocol:
- We target all static files, by scanning all web requests:
- for the image GIF, JPEG, PNG, SVG
- for the CSS and JS files
- and others HTML and XML files (as Atom, RSS, Sitemap, etc.)
- we apply a tag policy, with the option
tag
. - and finally, we send an header
Cache-Control
, labelled by the tag.
Next, we apply the http protocol to a target relay.
relayd: example
Code: relayd
ip4 = "public-address-ipv4"
http protocol "hw" {
match request path "/*.atom" tag "CACHE"
match request path "/*.css" tag "CACHE"
match request path "/*.gif" tag "CACHE"
match request path "/*.html" tag "CACHE"
match request path "/*.ico" tag "CACHE"
match request path "/*.jpg" tag "CACHE"
match request path "/*.js" tag "CACHE"
match request path "/*.png" tag "CACHE"
match request path "/*.rss" tag "CACHE"
match request path "/*.svg" tag "CACHE"
match request path "/*.xml" tag "CACHE"
match response tagged "CACHE" header set "Cache-Control" value "public, max-age=86400"
tcp { nodelay, sack, socket buffer 65536, backlog 100 }
pass
}
relay "www" {
listen on $ip4 port 80
protocol hw
forward to 127.0.0.1 port 80
}