Skip to content

Instantly share code, notes, and snippets.

@ebouchut
Last active January 27, 2021 20:35
Show Gist options
  • Select an option

  • Save ebouchut/1939752 to your computer and use it in GitHub Desktop.

Select an option

Save ebouchut/1939752 to your computer and use it in GitHub Desktop.

Revisions

  1. ebouchut revised this gist Apr 25, 2019. No changes.
  2. ebouchut created this gist Feb 29, 2012.
    43 changes: 43 additions & 0 deletions LighttpdReverseProxyURLRewriting
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    #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
    )
    )
    )
    }