_ _
___ | |__ __ _ _______ | |_
/ _ \| '_ \ / _` |_ / _ \| __|
| (_) | | | | (_| |/ / (_) | |_
\___/|_| |_|\__,_/___\___/ \__|
httpd —
OpenBSD httpd configuration
| NOTE: All commands need to be executed with root. |
- Copy the examples httpd.conf to /etc, if it
doesn't exist:
cp /etc/examples/httpd.conf
/etc/
- Create the server directory:
mkdir
/var/www/htdocs/[SERVER_NAME]
defaults
| 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
}
- Create the authentication file in /var/www:
htpasswd
/var/www/[SERVER_NAME]_htpasswd [USER]
- Ensure the file is owned by www:
chown www:www
/var/www/[SERVER_NAME]_htpasswd
- 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
}
- Ensure the configuration is correct.
httpd -dvvvvvv
- Add -n to only verify the config file without running the server.
- Enable the httpd service:
rcctl enable httpd
- 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)
| 2026-07-14 |
: updated links: roman zolotarev |
| 2025-10-23 |
: added rewrite example. |
| 2025-10-03 |
: Created. |