shithub: tcp80

ref: be84ca6fe75bf5b400d1247a57edf0390a7c19e1
dir: /README.md/

View raw version
# To run the shithub software:

`/rc/bin/service/tcp80`:

```
#!/bin/auth/box -r/mnt -r/usr/git -r/sys/lib/ -r/usr/ori -r/usr/web -r/sys/lib/shithub -r/n -r/dev -eMa -s

<[3]/srv/clone{
	d=`{<[0=3]read}
	bind /srv/$d /srv
	# ugly, but we don't want to leak the clone fd into
	# procs that may stick around.
	<[3=0]{
		bind /usr/web /mnt/static
        exec /bin/tcp80 -r /sys/lib/tcp80 >>[2]/sys/log/httpd/log
	}
}
```

`/rc/bin/service/tcp443`:

```
#!/bin/auth/box -r/mnt -r/usr/git -r/sys/lib/ -r/usr/ori -r/usr/web -r/sys/lib/shithub -r/n -r/dev -eMa -s

<[3]/srv/clone{
	d=`{<[0=3]read}
	bind /srv/$d /srv
	# ugly, but we don't want to leak the clone fd into
	# procs that may stick around.
	<[3=0]{
		bind /usr/web /mnt/static
        exec tlssrv -c/sys/lib/tls/cert.pem -lhttpd -r`{cat $3/remote} /bin/tcp80 -r /sys/lib/tcp80 >>[2]/sys/log/httpd/log
	}
}
```

`/lib/namespace.httpd`:

```
bind /mnt/static /usr/web/static
```

It is possible to redirect error pages by passing `-e error`, like
`tcp80 -e 404 -e 403`. This will send a `301 Moved Permanently` to
e.g. `/404` or `/403`. It will also append the path to it:
Attempting to access `http://server/nopage.html` would redirect to
`http://server/404/nopage.html`.


It is also possible to define a set of hostnames to change the bind mounts for
`/usr/web` based on the Host header. To use this feature, you pass
`-h file` to tcp80. The format of the file is the same as that for execfs,
a regex for the hostname, any number of tabs, with a path to be mounted over
`/usr/web`.

```
server1.domain.com          /usr/webroot/server1
aardvark.different.org      /usr/webroot/aardvark
```

This does not affect execfs scripts directly, although the bind mounts happen
prior to their execution. If you are using the same scripts for multiple
hostnames, you can check the environment using `ns` to find out what is
mounted over `/usr/web`. If you are using shithub, or anything similar which
hooks on `/index.html`, it will still take precedence over any static files.

You can work around this by not hooking `/index.html`, instead hook something
like `/shithub.html` and then redirect to it.