Sample Header Ad - 728x90

OpenBSD httpd.conf conditionals

4 votes
1 answer
1592 views
_Note: this question is about the [built-in OpenBSD http server named httpd](http://openbsd.su/src/usr.sbin/httpd/) and its configuration. It does not apply to any other web servers._ Is it possible to make runtime conditional configurations of the new OpenBSD http server httpd? A naïve example would be server "myserver.com" { if $REMOTE_ADDR == "127.0.0.1" block drop } to disallow local access. Another, perhaps more relevant and illuminating, example would be in the case I am implementing an interface to a remote service that runs from a specific place, then I would benefit from something like remote_service1_ip = "192.168.0.1" server "myserver.com" { location "/remote_service1_api/" { if $REMOTE_ADDR != $remote_service1_ip block drop } } If this is possible, what is the correct way of doing it? More generally - there are a number of predefined macros specified in the man-page of OpenBSD-httpd.conf as described in the block: $DOCUMENT_URI The request path. $QUERY_STRING The optional query string of the request. $REMOTE_ADDR The IP address of the connected client. $REMOTE_PORT The TCP source port of the connected client. $REMOTE_USER The remote user for HTTP authentication. $REQUEST_URI The request path and optional query string. $SERVER_ADDR The configured IP address of the server. $SERVER_PORT The configured TCP server port of the server. $SERVER_NAME The name of the server. %n The capture index n of a string that was captured by the enclosing location match option. and I would like to know how to use them. Using $REMOTE_ADDR in a redirection context seems rather silly to me, and I guess there should be something else to use them for, but I can't find or understand any such use case in the documentation.
Asked by Bex (768 rep)
Apr 8, 2016, 01:00 PM
Last activity: Jul 4, 2016, 04:28 AM