« Back

How to run a webserver with httpd on OpenBSD 6.3

Set up a simple webserver to serve static pages like a jekyll blog.

OpenBSD comes with a built-in webserver called httpd, written by Reyk Flöter.

So that means in contrast to most Linux distributions, this is not a rebranded version of the Apache webserver. Instead, it’s a very basic webserver.

The idea behind this is very much in line with the larger OpenBSD philosophy that security is top priority and performance may take a hit in achieving that.

Basic configuration

Populate /etc/httpd.conf and replace example.com with your domain

server "example.com" {
  listen on * port 80
  root "/htdocs/example.com"
}
The httpd daemon is chrooted to /var/www by default. So `/htdocs/example.com` means `/var/www/htdocs/exmaple.com` here.

That’s the whole configuration you need. Now we create our document root on the filesystem and add a simple index.html placeholder.

mkdir -p /var/www/htdocs/example.com
echo "Hello World from OpenBSD 6.3" > /var/www/htdocs/example.com/index.html

You can check your configuration with

httpd -n

When everything looks good, we can enable (start on boot) and start httpd

rcctl enable httpd
rcctl start httpd

Now you should reach your website with your IP address. That is a very basic configuration to serve static content, you can read more about in the manpage HTTPD.CONF(5). If you like, you can configure HTTPS with Let’s encrypt now.