3

How to redirect an http request to specific page using OpenBSD's httpd; for example, I'm serving up OpenBGPd bgplg like so in httpd.conf:

ext_addr="127.0.0.1"

server "www.example.conf" {
listen on $ext_addr port 80
        location "/cgi-bin/*" {
                fastcgi
                root ""
        }
}

How to make it possible to redirect www.example.com to www.example.com/cgi-bin/bgplg, rather than having to type exactly www.example.com/cgi-bin/bgplg.

I tried a few options but none seems to work. Thanks

1 Answer 1

1

To use a simple block return redirect, it needs a specific / location block or it will infinitely loop (noting that the location block / is without a wildcard so assets can bypass)

server "www.example.conf" {
    listen on $ext_addr port 80
        location "/cgi-bin/*" {
                fastcgi
                root ""
        }

        location "/" {
                # 302 (Temporary) while testing
                # 301 (Permanent) when you're done & sure
                block return 302 "/cgi-bin/bgplg"
        }
}

Now, there is another trick that generally works: root is passed through to fastcgi as the DOCUMENT_ROOT variable, which is executed if it exists.

A side effect is that httpd doesn't set the SCRIPT_NAME which bgplg requires and thus doesn't work; but other scripts that don't rely on it, or gracefully handle this will work fine, (and can either handle / alone, or be extended with pattern matching or /* as a catch-all)

location "/" {
        fastcgi
        root "/cgi-bin/somescript"
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .