.Dd Created:2025-10-03|Updated:2025-10-23| .de ocsi \\$* , .. .de oxr .ocsi .Xr \\$* .. .de oit .It \\$* .. .de obdi .Bl -dash -compact .oit \\$* .. .de obdl .Bd -literal -compact \\$* .. .de onote .Bl -hang -compact .oit \\$* .El .. .de ocomm .Bl -diag -compact .oit \\$* .El .. .de opsy .Pp .Sy - \\$* .. .de obc .Bl -column \\$* .. .de obc2 .obc opt desc .. .de obc3 .obc option arguments description .. .Dt HTTPD oh .Os OpenBSD 7.7| .Nm httpd .Nd OpenBSD httpd configuration .onote NOTE: All commands need to be executed with root. .Bl -enum -compact .oit Copy the examples .Pa httpd.conf to /etc, if it doesn't exist: .Dl cp /etc/examples/httpd.conf /etc/ .oit Create the server directory: .Dl mkdir /var/www/htdocs/[SERVER_NAME] .El .Ss httpd.conf .Em defaults .Bl -column -offset indent ".Sy roff_supported (oh) " .It chroot Ta : /var/www .It root Ta : /var/www/htdocs .It directory index Ta : index.html .El .obdl server "default" { listen on * port 80 root "/htdocs/[SERVER_NAME]" } .Ed .Ss locations .obdi location "/location/" will apply to the directory. .oit location "/location/*" will also apply to subdirectories. .El .Ss directory listing This configuration goes inside the server block. .obdl location "/[DIR_LIST_PATH]/*" { directory auto index } .Ed .Ss authentication .Bl -enum -compact .oit Create the authentication file in /var/www: .Dl htpasswd /var/www/[SERVER_NAME]_htpasswd [USER] .oit Ensure the file is owned by www: .Dl chown www:www /var/www/[SERVER_NAME]_htpasswd .oit Add the location block with authention: .obdl location "/[LOGIN_LOCATION]/*" { authenticate "realm" with "[SERVER_NAME]_htpasswd" } .Ed .Ss mime types .obdl 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 } .Ed .Sh HTTPD .Bl -enum -compact .oit Ensure the configuration is correct. .Dl httpd -dvvvvvv .Bl -diag -compact .oit Add -n to only verify the config file without running the server. .El .oit Enable the httpd service: .Dl rcctl enable httpd .oit Restart httpd after any change to /etc/httpd.conf: .Dl rcctl restart httpd .D1 If there is an error, it will show the line number, otherwise, it returns (ok). .El .Sh REWRITE Example: when a document is not found in the spanish section, it will take the user to the english document. .obdl location not found match "/es/(.*)" { request rewrite "/%1" } .Ed .Sh EXAMPLE .obdl 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 } .Ed .Sh TODO .obdi Improve rewrite example. .oit Add example for directory index. .oit Add chroot example. .oit Check mime type log as it gave a syntax error at some point. .oit Add better errors section. .El .Sh SEE ALSO .oxr web oh .oxr openbsd oh .Xr cgi oh .opsy config example files: .In /conf/httpd.conf .opsy OpenBSD manpages: .oxr httpd 8 .oxr httpd.conf 5 .Xr rcctl 8 .Ss links .obc2 .It - Lk https://github.com/reyk/httpd OpenBSD httpd .It - Lk https://www.fossil-scm.org/home/doc/trunk/www/server/openbsd/fastcgi.md Serving Fossil via httpd on OpenBSD: .It - Lk https://dev.to/nabbisen/setting-up-openbsds-httpd-web-server-4p9f Setting Up OpenBSD's httpd Web Server .It - Lk https://www.bsdhowto.ch/webserver.html BSDHowTo.ch - How to setup a web server with OpenBSD .It - Lk https://romanzolotarev.com/openbsd/httpd.html roman zolotarev - Configure httpd(8) on OpenBSD .El .Sh AUTHORS .An -nosplit .Xr ohazot oh | .Xr about oh | .Lk https://ohazot.com ohazot.com .Aq Mt admin@ohazot.com