Lighttpd Reverse Proxy Settings
Asked Answered
K

1

5

I am trying to configure Lighttpd to act as a reverse proxy. I want to have several URLs that are proxied to different servers on different ports, either on the same machine or within the local network.

For example:

/ /static /socket /ajax

Lighttpd would proxy all of the connections except those to /static. I want to serve all requests to /static directly from this instance of lighttpd.

Here is the config file for mod_proxy:

##
# Serve Static Content via Lighttpd.
#
$HTTP["url"] =~ "^/static/" {
    server.document-root = "/path/to/my/static/files"
    accesslog.filename = rootdir + "/var/log/static.log"
    server.errorlog = rootdir + "/var/log/static.error.log"
}
##
# Proxy to instance of Socket.io.
#
else $HTTP["url"] =~ "^/socket/" {
    accesslog.filename = rootdir + "/var/log/socket.log"
    server.errorlog = rootdir + "/var/log/socket.error.log"
    proxy.server  = (
        "" => ( (
            "host" => "127.0.0.1",
            "port" => 3000
        ) )
    )
}
##
# Proxy to AJAX backend.
#
else $HTTP["url"] =~ "^/ajax/" {
    accesslog.filename = rootdir + "/var/log/ajax.log"
    server.errorlog = rootdir + "/var/log/ajax.error.log"
    proxy.server  = (
        "" => ( (
            "host" => "127.0.0.1",
            "port" => 4000
        ) )
    )
}
##
# Proxy to something that returns my layout.
#
else $HTTP["url"] =~ "^/" {
    accesslog.filename = rootdir + "/var/log/root.log"
    server.errorlog = rootdir + "/var/log/root.error.log"
    proxy.server  = (
        "" => ( (
            "host" => "127.0.0.1",
            "port" => 5000
            ) )
    )
}

I am pretty sure that my regular expressions are wrong. I also think the else stringing is wrong. I am just not sure how else to do it. I am new to this area, so I would appreciate some nudges in the right direction.

Thanks,

Kussell answered 19/2, 2012 at 19:9 Comment(0)
B
2

Strictly speaking, the else blocks should be unnecessary.

As to your actual problem, you state in your question you want to match /ajax, but your regex looks for /ajax/ (note the trailing slash). What is the URL you are requesting?

Burger answered 19/2, 2012 at 21:15 Comment(3)
The main point of using the reverse proxy, at least in my case, is to circumvent the same origin policy. Therefore, my use case would be posting data and not reallying caring about about anything past the initial /ajax. The exception to this is the /static. I need to preserve the request in its entirety to serve the correct static content.Kussell
By url, do you mean domain? I just want lighttpd to match based on the url, regardless of the domain. Did I misunderstand?Kussell
No, I just mean the path part (after the domain). I'm only pointing out the trailing slash in this answer :)Burger

© 2022 - 2024 — McMap. All rights reserved.