Image by Taken from Pixabay

OpenBSD httpd — Website Maintenance

phbits

--

The default web server in OpenBSD is httpd. A lightweight server with only the essentials and built secure from the ground up.

There are occasions when a website must be placed into maintenance and httpd.conf makes this easy with pattern matching.

Tested on: OpenBSD 6.6 GENERIC

Create Maintenance Page

Save the following (or similar) page to the website root as maintenance.html.

This technique will redirect all requests which is why no other files are referenced. Any styles or scripts must be specified directly in the maintenance page or hosted on a different website.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Website Under Maintenance</title>
<meta name="description" content="Website Under Maintenance">
<meta name="author" content="phbits">
<style>html, body { height: 100%; font-family: 'Courier'; } .listed-item { display: flex; justify-content: center; align-items: center; }</style>
</head>
<body>
<div class="listed-item">
<h1>Website Under Maintenance</h1>
</div>
</body>
</html>

Update httpd.conf

Update the target website in httpd.conf as follows. The first location match will correctly display maintenance.html. All other requests will be picked up by the second location match resulting in a redirect to the maintenance page.

Two points worth pointing out about this method are:

  1. Will redirect any request NOT for maintenance.html (e.g. favicon.ico, images, css, js, etc.).
  2. HTTP 302 is being used as the redirect since it is temporary and thus shouldn't impact search engine placement.
public_ip="1.1.1.1"server "website.domain.com" {
listen on $public_ip port 80
directory no auto index
location match "^/maintenance.html$" {
root "/htdocs/website.domain.com"
}
location match ".*" {
block return 302 "https://website.domain.com/maintenance.html"
}
}

Check httpd.conf is valid

Always a good idea to check that httpd.conf is valid after making a change.

httpd -n

Restart httpd

With a valid httpd.conf, restart httpd.

rcctl restart httpd

Test

Test the new configuration by ensuring the following two points are true.

  1. Requests to website.domain.com/maintenance.html successfully displays the maintenance page.
  2. All other requests to website.domain.com result in an HTTP 302 Found and redirect to the maintenance page.

--

--