OpenBSD httpd 6.3: Web server
- Network services
- Published
- 3 min read
- @nabbisen
Table of contents
Intro Intro
OpenBSD has its own web server called “httpd (opens in a new tab)”.
Backgrounds Backgrounds
It’s possible on OpenBSD to install Nginx (opens in a new tab) and Apache (opens in a new tab) (called “apache-httpd”).
They are not supported officially, however, because of historical backgrounds (opens in a new tab). Nginx disappeared from the official manual at the end of 5.6 release (opens in a new tab) in 2015. OpenBSD httpd was added then.
It’s also possible to install Caddy (opens in a new tab) manually.
To be frank, OpenBSD httpd seems to have less conf examples and tutorials than them. Therefore, some might think it more difficult.
I love OpenBSD httpd, for it’s simple and minimal with clearly licensed (opens in a new tab), robust and secure, and thus, to my feelings, it’s beautiful. Also, it becomes more powerful with relayd (opens in a new tab).
Environment Environment
- OS: OpenBSD 6.3 amd64
Procedure Procedure
1. Prepare a configuration file 1. Prepare a configuration file
httpd.conf (opens in a new tab) is required in order to activate httpd service.
The default path is /etc/httpd.conf .
1-1. Make /etc/httpd.conf 1-1. Make /etc/httpd.conf
# # Using fish shell:
# if not test -e /etc/httpd.conf; \
touch /etc/httpd.conf; \
end
Of course, simply using touch /etc/httpd.conf or vi /etc/httpd.conf are all right.
1-2. Edit /etc/httpd.conf 1-2. Edit /etc/httpd.conf
#[ MACROS ]
ext_ip = "127.0.0.1"
# ext_ip = "*" # open to the outside network
# ext_ip = "egress" # open to only the primary IP address of the network interface
# [ GLOBAL CONFIGURATION ]
# none
# [ SERVERS ]
server "default" {
listen on $ext_ip port 80
root "/htdocs/my.domain"
}
# [ TYPES ]
types {
include "/usr/share/misc/mime.types"
}
(caution) root property in “SERVERS” section means the directories under /var/www . The official document mentions in GLOBAL CONFIGURATION (opens in a new tab) section:
chroot directory Set the chroot(2) directory. If not specified, it defaults to /var/www, the home directory of the www user.
Add other server definitions optionally like these:
server "www.https-example.domain" {
alias "https-example.domain"
listen on $ext_ip port 80
listen on $ext_ip tls port 443
tls {
key "/etc/ssl/private/www.https-example.domain.key"
certificate "/etc/ssl/www.https-example.domain.crt"
}
root "/htdocs/www.https-example.domain"
}
server "www.fastcgi-example.domain" {
alias "fastcgi-example.domain"
listen on $ext_ip port 80
fastcgi socket ":{% port-number %}"
}
The official document is here (opens in a new tab) .
1-3. Make index.html for testing 1-3. Make index.html for testing
# mkdir -p /var/www/htdocs/my.domain
# chown {% user %}:{% group %} /var/www/htdocs/my.domain # if necessary
$ echo "Hello, world. from OpenBSD httpd" > /var/www/htdocs/my.domain/index.html
2. Activate httpd service 2. Activate httpd service
Enable httpd:
# rcctl enable httpd
* note: This time /etc/rc.conf.local is created like this:
# cat /etc/rc.conf.local
httpd_flags=
And start it:
# rcctl start httpd
httpd(ok)
* note: Under the default setting: httpd_flags=NO, # rcctl -f start httpd can start httpd forcely.
3. Test if the server is listening 3. Test if the server is listening
$ curl localhost:80
Hello, world. from OpenBSD httpd
Outro Outro
Thank you very much for your reading. Happy serving 🕊
More on: Run web, mail and federated services
-
Tor 🧅 provides highly private access 👯 to the Web ✨
-
Lemmy is one of Fediverse implementations, which focuses on link aggregators.
-
This post is a part of Lemmy 0.16.7 on OpenBSD 7.2 about Lemmy.
OBSD Solutions
OBSD Solutions: OpenBSD consulting and support by Scqr, Reflerd Inc. (opens in a new tab)
Comments and feedback are welcome.