OpenBSD httpd 6.3: Web Server
Tags: openbsd, httpd, web, server
Published: 2018-10-05 02:53:20

---
title: OpenBSD httpd 6.3: Web Server
published: true
description: OpenBSD has its own web server called "httpd". It is a robust and secure one. This post shows how to set it up.
tags: openbsd, httpd, web, server
series: OpenBSD web server
cover_image: https://thepracticaldev.s3.amazonaws.com/i/c5xs8vrwe9jxh7i84mvm.jpg
canonical_url: https://obsd.solutions/en/blog/2018/10/05/openbsd-httpd-63-web-server/index.html
---

## Intro

OpenBSD has its own web server called "[httpd](https://man.openbsd.org/httpd.8)".

---

### Backgrounds

It's possible on OpenBSD to install [Nginx](https://www.nginx.com/resources/wiki/start/topics/tutorials/openbsd/) and [Apache](http://httpd.apache.org/) (called "apache-httpd").

They are not supported officially, however, because of [historical backgrounds](https://www.openbsd.org/papers/httpd-asiabsdcon2015.pdf).
Nginx disappeared from the official manual at the end of [5.6 release](https://man.openbsd.org/OpenBSD-5.6/man8/nginx.8) in 2015.
OpenBSD httpd was added then.

It's also possible to install [Caddy](https://caddyserver.com/download) 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](https://cvsweb.openbsd.org/src/share/misc/license.template?rev=HEAD), robust and secure, and thus, to my feelings, it's beautiful.
Also, it becomes more powerful with [relayd](https://man.openbsd.org/relayd.8).

<center>✿ ✿ ✿</center>

### Environment

- OS: OpenBSD 6.3 amd64

## Procedure

### 1. Prepare a configuration file

[`httpd.conf`](https://man.openbsd.org/httpd.conf.5) is required in order to activate httpd service.
The default path is `/etc/httpd.conf` .

#### 1-1. Make `/etc/httpd.conf`

```shell-session
# # 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`


```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](https://man.openbsd.org/httpd.conf.5#GLOBAL_CONFIGURATION) 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:

```conf
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](https://man.openbsd.org/httpd.conf.5) .

#### 1-3. Make index.html for testing

```shell-session
# 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

Enable httpd:

```shell-session
# rcctl enable httpd
```

*\* note: This time `/etc/rc.conf.local` is created like this:*

```shell-session
# cat /etc/rc.conf.local
httpd_flags=
```

And start it:

```shell-session
# 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

```shell-session
$ curl localhost:80
Hello, world. from OpenBSD httpd
```

<center>✿ ✿ ✿</center>

## Outro

Thank you very much for your reading.
Happy serving 🕊