1

I have a website www.somewebsite.com domain hosted on lighttpd 1.4 server configured with server.port = 8080 that is on a device (A) with local IP 192.168.1.26 and I want to get to use a reverse proxy in order to access another server that runs on a different device (B) at 192.168.1.30:80/myappin order to be accessed as

somewebsite.com/myapp

In device (A) server config I have enabled mod_proxy and I have tried to add

$HTTP["url"] =~ "^.*myapp" {
    proxy.server  = ( "" => 
        (( "(www.)?somewebsite.com" => "192.168.1.30", "port" => 80 ))
    )
}

but I get internal server error page when I try to access somewebsite.com/myapp

I have tried also

$HTTP["url"] =~ "(^/myapp/)" {   
  proxy.server  = ( "" => ("" => ( "(www.)?somewebsite.com" => "127.0.0.1", "port" => 8080 ))) 
}

$SERVER["socket"] == ":81" {   
  url.rewrite-once = ( "^/myapp/(.*)$" => "/$1" )   
  proxy.server  = ( "" => ( "" => ( "(www.)?somewebsite.com" => "192.168.1.30", "port" => 80 ))) 
}

but the result is even worse and server crashes completely

AndreaF
  • 205
  • 1
  • 8

2 Answers2

2

proxy.server do not take host as an argument, and "host" is a keyword, not a place to put your host here.

Try this:

$HTTP["host"] =~ "(www.)?somewebsite.com" {
 $HTTP["url"] =~ "^/myapp/" {
  url.rewrite-once = ("^/myapp/(.*)" => "/newapp/$1") # If you need to rewrite context.
  proxy.server  =  ( "" => ( "" => ("host" => "192.168.1.30", "port" => 80 )))
  }
}
kab00m
  • 398
  • 1
  • 9
  • Thanks for the help. I have flushed DNS cache and it works. However if I want to alias the `/myapp` subpath linked with reverse proxy using another name e.g. `somewebsite.com/othername` how should I do? – AndreaF Oct 31 '20 at 20:54
  • Look at my edited answer. – kab00m Nov 01 '20 at 13:02
  • @kaboom I have tried but unfortunately this doesn't work. I get not found error if I try to access `somewebsite.com/newapp` – AndreaF Nov 01 '20 at 16:57
  • You have to look into both lighttpd and backend logs - what url is coming and what error is produced. And also check browser internals via "inspect" mode. It may be a specific of how backend works. – kab00m Nov 02 '20 at 08:29
  • seems that `url.rewrite` doesn't work in `HTTP["url"]` block – AndreaF Nov 02 '20 at 21:48
  • It was a bug before 1.4.34, you may still hit it. Anyway it should be out of "url" block not to confuse original context and proxy context. – kab00m Nov 03 '20 at 15:28
1
$HTTP["host"] =~ "(www.)?somewebsite.com" {
  $HTTP["url"] =~ "^/myapp/" {
    url.rewrite-once = ("^/myapp/(.*)" => "/newapp/$1")
  }
  $HTTP["url"] =~ "^/newapp/" {
    proxy.server  =  ( "" => ( "" => ("host" => "192.168.1.30", "port" => 80 )))
  }
}

Alternatively, you can use proxy.header with "map-urlpath" with lighttpd 1.4.46 and later. See https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModProxy

gstrauss
  • 221
  • 1
  • 5