Skip to content

Instantly share code, notes, and snippets.

@ebouchut
Last active January 27, 2021 20:35
Show Gist options
  • Save ebouchut/1939752 to your computer and use it in GitHub Desktop.
Save ebouchut/1939752 to your computer and use it in GitHub Desktop.
Lighttpd reverse-proxy to that matches an URL _and_ does URL rewriting #web #server #lighttpd
#server.modules += ( "mod_rewrite")
# Workaround to have a working reverse-proxy that matches an URL does URL rewriting in Ligghtpd.
#
# Ligtthpd 1.4.28 cannot perform both matching and URL rewriting at the same time.
# Therefore we need to define 2 proxies, one does the matching and bounce the request
# to the other one, in charge of rewriting the URL before proxying the request to the target server.
#
# More about this here:
# http://redmine.lighttpd.net/issues/164#note-9
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# $HTTP["url"] =~ /servername/path
# => 127.0.0.1:82 (rewrite : remove "/servername")
# => servername:80/path
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Matching Proxy
#
$HTTP["url"] =~ "(^/servername/)" {
proxy.server = ( "" => (
"servername:80" => # name
( "host" => "127.0.0.1",
"port" => 82
)
)
)
}
# URL Rewriting Proxy
#
$SERVER["socket"] == ":82" {
url.rewrite-once = ( "^/servername/(.*)$" => "/$1" )
proxy.server = ( "" => (
"servername:82" => # name
( "host" => "10.0.0.1", # Set the IP address of servername
"port" => 80
)
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment