_                    _
  ___ | |__   __ _ _______ | |_
 / _ \| '_ \ / _` |_  / _ \| __|
| (_) | | | | (_| |/ / (_) | |_
 \___/|_| |_|\__,_/___\___/ \__|

httpdOpenBSD httpd configuration

NOTE: All commands need to be executed with root.
  1. Copy the examples httpd.conf to /etc, if it doesn't exist:
    cp /etc/examples/httpd.conf /etc/
  2. Create the server directory:
    mkdir /var/www/htdocs/[SERVER_NAME]

chroot : /var/www
root : /var/www/htdocs
directory index : index.html
server default {
	listen on * port 80
	root "/htdocs/[SERVER_NAME]"
}

- location /location/ will apply to the directory.
- location /location/* will also apply to subdirectories.

This configuration goes inside the server block.

location /[DIR_LIST_PATH]/* {
	directory auto index
}

  1. Create the authentication file in /var/www:
    htpasswd /var/www/[SERVER_NAME]_htpasswd [USER]
  2. Ensure the file is owned by www:
    chown www:www /var/www/[SERVER_NAME]_htpasswd
  3. Add the location block with authention:
    location /[LOGIN_LOCATION]/* {
    	authenticate "realm" with "[SERVER_NAME]_htpasswd"
    }

types {
	include "/usr/share/misc/mime.types"
	text/css css
	text/html
	text/plain txt oh sh awk bc
	image/gif gif
	image/jpeg jpeg jpg
	image/png png
	application/xml xml
}

  1. Ensure the configuration is correct.
    httpd -dvvvvvv
    Add -n to only verify the config file without running the server.
  2. Enable the httpd service:
    rcctl enable httpd
  3. Restart httpd after any change to /etc/httpd.conf:
    rcctl restart httpd
    If there is an error, it will show the line number, otherwise, it returns (ok).

Example: when a document is not found in the spanish section, it will take the user to the english document.

location not found match /es/(.*) {
	request rewrite "/%1"
}

(back to top)

server default {
	listen on * port 80
	root "/htdocs/[SERVER_NAME]"
	location "/[DIR_LIST_PATH]/*" {
		directory auto index
	}
	errdocs "[ERRORS_DIRECTORY]" #location for errors, such as 404.html, 403.html, 503,html, etc.
}
types {
	include "/usr/share/misc/mime.types"
	text/css css
	text/html html
	text/plain txt oh sh awk bc
}

(back to top)

- Improve rewrite example.
- Add example for directory index.
- Add chroot example.
- Check mime type log as it gave a syntax error at some point.
- Add better errors section.
- Review document on httpd on 7.9.
- Add block return.
- Translate to Spanish.

(back to top)

web, openbsd, cgi
config example files: </conf/httpd.conf>
OpenBSD manpages: httpd(8), httpd.conf(5), rcctl(8)
links
- OpenBSD httpd
- Serving Fossil via httpd on OpenBSD
- BSDHowTo.ch - How to setup a web server with OpenBSD
- roman zolotarev - Configure httpd(8) on OpenBSD

(back to top)

2026-07-14 : updated links: roman zolotarev
2025-10-23 : added rewrite example.
2025-10-03 : Created.

(back to top)

ohazot | about | ohazot.com <admin@ohazot.com>

This document applies to: OpenBSD 7.7| 2026-07-14