Skip to content

Instantly share code, notes, and snippets.

@zaimramlan
Last active November 13, 2016 12:05
Show Gist options
  • Save zaimramlan/003cb763f5f9a12b4632e71765799d95 to your computer and use it in GitHub Desktop.
Save zaimramlan/003cb763f5f9a12b4632e71765799d95 to your computer and use it in GitHub Desktop.
Reverse Proxy With Lighttpd
### Reverse Proxy Begins ###

# redirect all '/sub_directory' request to '/sub_directory/' so that all static files are
# serve in the 'sub_directory' directory instead of the root directory
url.redirect = ("^/sub_directory$" => "/sub_directory/")

# start a proxy server at port 8001 to serve at the url exactly beginning with '/sub_directory/'
$HTTP["url"] =~ "^/sub_directory/+" {
  proxy.server  = ( "" => ("" => ( "host" => "127.0.0.1", "port" => 8001 )))
}

# reverse the proxy server at port 8001 to another proxy server started
# at port 8000, where the webserver is served
$SERVER["socket"] == ":8001" {
    # rewrite any URL request beginning with '/sub_directory/', to root URL '/'
    # i.e. 127.0.0.1:8000/ <-- root URL
    url.rewrite-once = ("^/sub_directory/(.*)$" => "/$1")
    proxy.server = ( "" =>
    (
      "" =>
      ( "host" => "127.0.0.1",
        "port" => 8000
      )
    )
   )
}

### Reverse Proxy Ends ###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment