_ _ ___ | |__ __ _ _______ | |_ / _ \| '_ \ / _` |_ / _ \| __| | (_) | | | | (_| |/ / (_) | |_ \___/|_| |_|\__,_/___\___/ \__|
| ohazot | docs | links | dev | conf | txt |
| es | en |
| mdoc file |
| search |
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]
httpd.conf
| chroot | : /var/www |
| root | : /var/www/htdocs |
| directory index | : index.html |
server default {
listen on * port 80
root "/htdocs/[SERVER_NAME]"
}
locations
- location /location/ will apply to the directory.
- location /location/* will also apply to subdirectories.
directory listing
This configuration goes inside the server block.
location /[DIR_LIST_PATH]/* {
directory auto index
}
authentication
- 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" }
mime types
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
}
HTTPD
- 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 httpdIf there is an error, it will show the line number, otherwise, it returns (ok).
REWRITE
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"
}
EXAMPLE
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
}
TODO
- 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.
SEE ALSO
- config example files:
</conf/httpd.conf>
- OpenBSD manpages: httpd(8) , httpd.conf(5) , rcctl(8)
links
| - OpenBSD httpd |
| - Serving Fossil via httpd on OpenBSD: |
| - Setting Up OpenBSD's httpd Web Server |
| - BSDHowTo.ch - How to setup a web server with OpenBSD |
| - roman zolotarev - Configure httpd(8) on OpenBSD |