Proxy – How to Redirect by Port in Lighttpd

lighttpdPROXY

I'm really just starting out with lighttpd and I'm not sure how to configure this exactly.

I'm wanting to take traffic and redirect to another server say "http://localhost/url_a/" and redirect the request and responses from that to "http://other_server:8080/"

Another example would be "http://localhost/url_b/" going to "http://other_server:8081/url_b/"

What exactly should I look into for accomplishing this?

Thanks.

Best Answer

In Lighttpd 1.4 you need to use mod_proxy to forward the request to another server.

proxy.server = ("/url_a" => ((
    "host" => "1.2.3.4",
    "port" => 8080,
)))

Changing the URL path or virtual hostname is a bit tricky in 1.4. If you're using 1.5 you can use mod_proxy_core instead, which is more configurable:

$HTTP["url"] =~ "^/url_a" {
    proxy-core.protocol = "http"
    proxy-core.backends = ("other_server:8080")
    proxy-core.rewrite-request = (
        "_uri" => ( "^/url_a/?(.*)" => "/$1" ),
        "Host" => ( ".*" => "other_server" ),
    )
}