# obhttpd (OpenBSD HTTPD)



## MAHDTech (May 21, 2016)

I am trying to get the obhttpd package working, and must be missing a critical step somewhere.

1. Installed the package
`pkg install obhttpd`

2. Set the service to start on boot (/etc/rc.conf)


```
obhttpd_enable="YES"
obhttpd_flags='"
```

3. Created a basic configuration (/usr/local/etc/obhttpd.conf)


```
ext_ip="MY_EXT_IP"

server "default" {
listen on ext_ip port 80
root "/htdocs/default"
}
```

4. Created the directories and set the permissions


```
mkdir -p /var/www/htdocs/default
chown -R www:www /var/www
```

5. Start the service

`service obhttpd start`

6. Now I receive an error in /var/log/messages as follows


```
lost child: server exited abnormally
lost child: logger exited abnormally
```

What am I missing?


----------



## MAHDTech (May 21, 2016)

Ok, so I have gotten somewhere, if I run obhttpd in the foreground I get some additional logs


```
/usr/local/sbin/obhttpd -d -v

startup
fatal: proc_run: chroot: No such file or directory
fatal: proc_run: chroot: No such file or directory
lost child: logger exited abnormally
lost child: server exited abnormally
parent terminating, pid 9058
```

So what directory is it actually looking for as chroot?

From what I have read the default chroot to /var/www as / which would make make my "htdocs" appear as /var/www/htdocs. Is that right?


----------



## SirDice (May 23, 2016)

As this appears to be using chroot(8) you'll need to mount some devices on /var/www/dev/ (assuming it chroot(8)s to /var/www/). Aren't there any hints in /usr/local/etc/rc.d/obhttpd?


----------



## kaori.hinata (Jun 5, 2016)

chroot(8) is attempting to change root to a directory that doesn't exist. As the maintainer didn't actually update the obhttpd.conf(8) man page (beyond renaming it), it's not especially clear what the default value of the `chroot` setting is anymore, but it doesn't appear to be `/var/www` or `/usr/local/var/www`.

Try setting the top-level chroot option to a directory of your choosing:


```
chroot "/usr/local/var/www"
```

Provided your chosen `root` setting is correct relative to your chosen `chroot` setting, obhttpd should start without complaints.


----------



## Nulani (Jun 13, 2016)

If I interpret the code from http.c below correctly, it defaults to the home directory of 'www', which is /var/www on OpenBSD but /nonexistent on FreeBSD.


```
if (env->sc_chroot == NULL)
env->sc_chroot = ps->ps_pw->pw_dir;
for (proc = 0; proc < nitems(procs); proc++)
procs[proc].p_chroot = env->sc_chroot;
```


----------



## boun (Jun 25, 2016)

MAHDTech said:


> Ok, so I have gotten somewhere, if I run obhttpd in the foreground I get some additional logs
> 
> 
> ```
> ...


What was the solution to this?


----------



## Nulani (Jun 25, 2016)

Specify the chroot in httpd.conf, e.g:


```
chroot "/usr/local/www"
```
Otherwise it defaults to /nonexistent.


----------

