Setting up httpd webserver, and you want:

  • some static html please
  • display a directory listing autoindex style
  • try a dumb CGI script because why not?

This is basic tyre-kicking; please read my other posts on making a more complete httpd (and system, for that matter) configuration.

create a basic /etc/httpd.conf#

types { include "/usr/share/misc/mime.types" }

server "default" {
        listen on * port 80
        root "/htdocs"

        location "/cgi-bin/*" {
                root "/"
                fastcgi socket "/run/slowcgi.sock"
        }
}

enable slow cgi on boot, start it#

rcctl enable slowcgi
rcctl start slowcgi

create our test files#

static#

echo "Hello from OpenBSD httpd." | tee /var/www/htdocs/index.html

cgi#

nano /var/www/cgi-bin/ip.cgi, and paste in:#

#!/bin/sh
echo "Content-Type: text/plain"
echo ""
echo "Hello from OpenBSD httpd."
echo "Your IP is ${REMOTE_ADDR:-unknown}."

Note: This is for example only; I don’t endorse serving up #!/bin/sh via your webserver. :)

fix permissions#

chmod 755 /var/www/cgi-bin/ip.cgi
chown root:bin /var/www/cgi-bin/ip.cgi

httpd runs in chroot of /var/www, so we need a copy of /bin/sh there#

mkdir -p /var/www/bin
cp /bin/sh /var/www/bin/sh
chmod 555 /var/www/bin/sh

enable on boot, start it, check it is running#

rcctl enable httpd
rcctl start httpd

verify server works by browsing to it#

static, eg: http://<yourserver>/ will show:

Hello from OpenBSD httpd.

cgi, eg: http://<yourserver>/cgi-bin/ip.cgi

Hello from OpenBSD httpd.
Your IP is 10.0.2.1.

add an auto index directory#

Create “stuff” directory and fix permissions and we will enable auto indexing on it:

chown root:bin /var/www/htdocs/stuff
chmod 755 /var/www/htdocs/stuff

Add this to /etc/httpd.conf under existing location and before final }:

        location "/stuff/*" {
                directory {
                        auto index
                }
        }

Reload:

rcctl restart httpd

There’s nothing in the directory yet; try echo "bar" > /var/www/htdocs/stuff/foo.txt to get started.

Now test it, goto http://<yourserver>/stuff and you should see a nice auto indexing list.

Your website is terrible|amazing, glhf.

Reminder: Please read my guides on configuring HTTPS/TLS, and disabling unused services (eg: slowcgi might not be needed).