Operating System BSD

How to Set Up the httpd Web Server on OpenBSD 8.0

Serve a website from OpenBSD 8.0 with the httpd daemon from the base system: virtual hosts, rcctl, HTTPS with acme-client, logs and FastCGI.

OpenBSD ships its own web server, httpd, in the base system. There is nothing to install: you write a short /etc/httpd.conf, enable the daemon with rcctl and it serves static files, speaks TLS and hands dynamic requests to FastCGI. This guide sets up a site with virtual hosts and a free Let's Encrypt certificate on OpenBSD 8.0, the current release (October 2026). The same steps apply to other recent releases.

This is OpenBSD's own daemon, not Apache httpd. It has no .htaccess files and no loadable modules, and its whole configuration usually fits on one screen.

Requirements

  • A server running OpenBSD 8.0 with a public IP address.
  • A user that can run commands through doas, or a root shell.
  • For HTTPS: a domain name whose A (and AAAA) records point to the server. The examples use example.com and www.example.com.

Step 1: Create the document root

httpd locks itself into /var/www with chroot after it starts. Every path you write inside a server block is therefore relative to /var/www: the default document root /htdocs is really /var/www/htdocs. Create a directory per site and a test page:

doas mkdir -p /var/www/htdocs/example.com
echo '<p>It works on OpenBSD</p>' | doas tee /var/www/htdocs/example.com/index.html

The files only need to be readable by the unprivileged www user; they can stay owned by root.

Step 2: Write /etc/httpd.conf

A fresh system has no /etc/httpd.conf. A commented sample lives in /etc/examples/httpd.conf, but a minimal file is quicker to write by hand. Create /etc/httpd.conf with this content:

server "example.com" {
	alias "www.example.com"
	listen on * port 80
	root "/htdocs/example.com"
}

What the directives do:

  • server "name" starts a virtual host. The name is matched against the Host header and may contain wildcards such as *.example.com. The first server in the file also answers requests that match no name.
  • alias adds another name for the same site.
  • listen on * port 80 listens on every local address, IPv4 and IPv6. Instead of * you can give an address, an interface name or the group egress, which means the interface that holds the default route.
  • root is the document root inside the chroot.

To host more sites, add more server blocks with the same listen on line and a different name and root:

server "example.net" {
	listen on * port 80
	root "/htdocs/example.net"
}

You do not need a types section for an ordinary site, because httpd has a built-in list of common media types. If you serve unusual file types, load the system-wide list by adding this block outside any server:

types {
	include "/usr/share/misc/mime.types"
}

Step 3: Check the configuration and start httpd

Test the file first. The -n flag parses the configuration and exits:

doas httpd -n

When it prints configuration OK, enable the daemon so that it starts at boot, and start it now:

doas rcctl enable httpd
doas rcctl start httpd

rcctl enable writes the needed line to /etc/rc.conf.local for you. Older tutorials edit that file by hand and add httpd to pkg_scripts; that variable is only for daemons installed from packages and is wrong for a base-system daemon.

Confirm that the daemon is running and answers:

doas rcctl check httpd
ftp -o - http://203.0.113.10/

Replace 203.0.113.10 with your server's address. After every later change to /etc/httpd.conf, test and reload:

doas httpd -n && doas rcctl reload httpd

The default /etc/pf.conf lets incoming connections through, so ports 80 and 443 are reachable on a default install. If you run a stricter ruleset, add a rule such as pass in on egress proto tcp to port { 80 443 } and load it with doas pfctl -f /etc/pf.conf.

Step 4: Add HTTPS with acme-client

The base system also contains acme-client, which obtains certificates from Let's Encrypt using an HTTP challenge. The challenge files are written to /var/www/acme, and httpd has to serve them.

Serve the challenge directory

Add a location block to the port 80 server in /etc/httpd.conf:

server "example.com" {
	alias "www.example.com"
	listen on * port 80
	root "/htdocs/example.com"
	location "/.well-known/acme-challenge/*" {
		root "/acme"
		request strip 2
	}
}

Reload httpd as shown above.

Request the certificate

Copy the sample configuration and edit the domain section at the end:

doas cp /etc/examples/acme-client.conf /etc/acme-client.conf
doas vi /etc/acme-client.conf

For the example site the section looks like this. Leave the authority blocks above it unchanged.

domain example.com {
	alternative names { www.example.com }
	domain key "/etc/ssl/private/example.com.key"
	domain full chain certificate "/etc/ssl/example.com.fullchain.pem"
	sign with letsencrypt
}

Request the certificate. While you are still experimenting, change the last line to sign with letsencrypt-staging so that failed attempts do not count against the production rate limits.

doas acme-client -v example.com

Enable TLS in httpd

Now replace the site's configuration with two servers: one on port 80 that keeps answering challenges and redirects everything else, and one on port 443 that serves the site.

server "example.com" {
	alias "www.example.com"
	listen on * port 80
	location "/.well-known/acme-challenge/*" {
		root "/acme"
		request strip 2
	}
	location * {
		block return 301 "https://$HTTP_HOST$REQUEST_URI"
	}
}

server "example.com" {
	alias "www.example.com"
	listen on * tls port 443
	root "/htdocs/example.com"
	tls {
		certificate "/etc/ssl/example.com.fullchain.pem"
		key "/etc/ssl/private/example.com.key"
	}
}
doas httpd -n && doas rcctl reload httpd

Once HTTPS works for every name, you can add the single word hsts to the port 443 server to send a Strict-Transport-Security header.

Renew automatically

acme-client only contacts the certificate authority when the certificate is close to expiry, and it exits with a non-zero status when nothing changed, so it is safe to run often. Open root's crontab with doas crontab -e and add the line from the manual page:

~ * * * * acme-client example.com && rcctl reload httpd

The ~ picks a random minute, so the job runs once an hour.

Step 5: Logs

Logs are written inside the chroot, in /var/www/logs/access.log and /var/www/logs/error.log. The stock /etc/newsyslog.conf already rotates both files. Follow requests live with:

tail -f /var/www/logs/access.log

To get the referrer and user agent as well, add log style combined to a server block. To give a site its own files, add log access "example.com-access.log" and log error "example.com-error.log"; if you do, add those files to /etc/newsyslog.conf too.

Step 6: Dynamic content with FastCGI

httpd does not run scripts itself. It forwards requests to a FastCGI server over a socket that must live inside /var/www. For classic CGI programs, the base system includes slowcgi, which listens on /var/www/run/slowcgi.sock, the default socket of the fastcgi directive:

doas rcctl enable slowcgi
doas rcctl start slowcgi
	location "/cgi-bin/*" {
		fastcgi
		root "/"
	}

Put this block inside the server. The programs in /var/www/cgi-bin run inside the chroot too, so they must be statically linked or have their libraries copied into /var/www. For PHP, install PHP from packages with pkg_add, enable its FPM service with rcctl and point a location "*.php" block at the FPM socket with fastcgi socket; the package's readme in /usr/local/share/doc/pkg-readmes gives the exact service name and socket path for the version you installed.

Troubleshooting

  • 403 Forbidden on a directory: there is no index.html. Add the file, set another name with directory index, or allow listings with directory auto index.
  • 404 for files that exist: the root was written as a full path. Drop the leading /var/www.
  • httpd does not start: run doas httpd -dvv to keep it in the foreground with verbose output. A tls listener fails when the certificate or key file is missing, which is why the certificate is requested before port 443 is enabled.
  • Uploads fail with 413: the request body limit is 1 MB by default. Raise it with connection max request body followed by a size in bytes.

The full list of directives is in the httpd.conf(5) manual page; certificate handling is covered in acme-client(1).

Frequently asked questions

Is OpenBSD httpd the same as Apache?

No. OpenBSD removed Apache from its base system years ago and wrote its own small server with the same binary name. Apache is still available as a package if an application depends on .htaccess files or Apache modules.

How do I rewrite URLs without .htaccess?

Use location match with a pattern and request rewrite in /etc/httpd.conf, for example location match "/old/(.*)" { request rewrite "/new/%1" }. Patterns use Lua-style syntax, described in patterns(7), not regular expressions.

Can httpd act as a reverse proxy?

No. It serves files and talks FastCGI only. To forward HTTP requests to an application server, use relayd, which is also in the base system, in front of or instead of httpd.

Do I have to restart httpd after renewing the certificate?

A reload is enough. rcctl reload httpd makes the daemon reread its configuration, including the certificate files, which is what the cron job above does.

Share story:

Continue reading other guides on How VPS.