--- date: 2020-05-07T16:49:36+02:00 description: "How to caching static content with httpd & relayd, natives servers on OpenBSD" draft: false tags: ['relayd','Cache','httpd','HTTP','OpenBSD'] title: "Relayd: Web caching for httpd" translationKey: "relayd-web-caching" --- ## 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 "web-httpd-relayd-cache-example" relayd >}} ## Documentations ### Manpages * {{< man httpd 8 >}}, {{< man "httpd.conf" 5 >}} ----