Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lighttpd Reverse Proxy Settings

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,

like image 897
Jonathan Avatar asked Nov 04 '22 05:11

Jonathan


1 Answers

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?

like image 166
David Souther Avatar answered Nov 12 '22 16:11

David Souther