Using OpenBSD httpd as proxy

Starting from version 5.7 OpenBSD includes a minimal (truly minimal) web server with FastCGI support

(http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man8/httpd.8?query=httpd&sec=8)

The first step to enable it is writing its configuration file /etc/httpd.conf

  1. server "default" {
  2. listen on 0.0.0.0 port 80
  3.  
  4. fastcgi socket ":3031"
  5. }

then enable and start it with the rcctl tool:

  1. rcctl enable httpd
  2. rcctl start httpd

this minimal configuration will spawn a chrooted webserver on port 80, running as user ‘www’ and forwarding every requestto the address 127.0.0.1:3031 using the FastCGI protocol.

Now you only need to spawn uWSGI on the FastCGI address:

  1. [uwsgi]
  2. fastcgi-socket = 127.0.0.1:3031
  3. ; a simple python app (eventually remember to load the python plugin)
  4. wsgi-file = app.py

you can obviously use uWSGI as a full-featured CGI server (well, effectively it has way more features than every cgi server out there :P),just remember to force the modifier1 to the ‘9’ one:

  1. [uwsgi]
  2. fastcgi-socket = 127.0.0.1:3031
  3. fastcgi-modifier1 = 9
  4. ; a simple cgi-bin directory (eventually remember to load the cgi plugin)
  5. cgi = /var/www/cgi-bin

now you can place your cgi scripts in /var/www/cgi-bin (remember to give them the executable permission)

You can use UNIX domain sockets too, just remember the httpd servers runs chrooted in /var/www so you have to bind uWSGI sockets in a dir under it:

  1. [uwsgi]
  2. fastcgi-socket = /var/www/run/uwsgi.socket
  3. fastcgi-modifier1 = 9
  4. ; a simple cgi-bin directory
  5. cgi = /var/www/cgi-bin
  1. server "default" {
  2. listen on 0.0.0.0 port 80
  3.  
  4. fastcgi socket "/run/uwsgi.socket"
  5. }

If you want to forward only specific paths to uWSGI, you can use a location directive:

  1. server "default" {
  2. listen on 0.0.0.0 port 80
  3.  
  4. location "/foo/*" {
  5. fastcgi socket ":3031"
  6. }
  7.  
  8. location "/cgi-bin/*" {
  9. fastcgi socket ":3032"
  10. }
  11. }

Notes

Currently (may 2015) httpd can connect only to tcp fastcgi sockets bound on address 127.0.0.1 and to unix domain sockets