[UE] $HTTP["url"] inside $HTTP["host"] does not work, lighttpd 1.4.55, ubuntu 20.04
Added by aurora about 3 years ago
Hi,
i am developing a Javascript SPA with a PHP API backend, that must both be served from the same domain. On production the SPA is built to static html/javascript files and i have essentially the following configuration, that works:
$HTTP["host"] == "example.com" { server.name = "example.com" server.document-root = ROOT_DIR + "/frontend/build/" fastcgi.server = ( "/index.php" => (( "socket" => "/run/php/php8.1-fpm.sock", "broken-scriptfilename" => "enable", "allow-x-send-file" => "enable", "docroot" => ROOT_DIR + "/backend/host/", "check-local" => "disable" )) ) url.rewrite-once = ( "^/(api/.*)$" => "/index.php/$1", ) }
However, during development i do not want to serve the static SPA, but use a reverse proxy to serve the SPA using nodejs. So on the development machine i tried to use the following configuration, which does not work, because apparently the rule $HTTP["url"] !~ "^/api/" does not match:
$HTTP["host"] == "example.com" { fastcgi.server = ( "/index.php" => (( "socket" => "/run/php/php8.1-fpm.sock", "broken-scriptfilename" => "enable", "allow-x-send-file" => "enable", "docroot" => ROOT_DIR + "/backend/host/", "check-local" => "disable" )) ) $HTTP["url"] !~ "^/api/" { proxy = ( "" => (( "host" => "127.0.0.1", "port" => 3000 )) ) } url.rewrite-once = ( "^/(api/.*)$" => "/index.php/$1", ) }
Trying to access SPA results in a "403 Forbidden", debug-log reveals, that LightTPD is searching for the files in the default location "/var/www/html" instead of using the proxy. Serving the PHP backend still works. What am i doing wrong? Thanks!
Replies (4)
RE: $HTTP["url"] inside $HTTP["host"] does not work, lighttpd 1.4.55, ubuntu 20.04 - Added by aurora about 3 years ago
Looking again at the configuration, i just noticed that my mistake is writing "proxy =" instead of "proxy.server =" ... now it works and i feel really stupid, because i tried a whole day getting this to work. Sorry for the fuss, i think this can be closed.
RE: $HTTP["url"] inside $HTTP["host"] does not work, lighttpd 1.4.55, ubuntu 20.04 - Added by gstrauss about 3 years ago
mistakes happen. I edited your response to remove your self-judgement, but left your "feeling".
Tip for the future: you can test your config using lighttpd -f /etc/lighttpd/lighttpd.conf -tt
. In the above situation, you would have seen some error trace for unrecognized directive "proxy".
RE: [UE] $HTTP["url"] inside $HTTP["host"] does not work, lighttpd 1.4.55, ubuntu 20.04 - Added by aurora about 3 years ago
thanks for editing :-) ... yes, i also used the test-flags but -t showed "syntax OK" and -tt didn't return anything. So i thought the config must be ok.
RE: [UE] $HTTP["url"] inside $HTTP["host"] does not work, lighttpd 1.4.55, ubuntu 20.04 - Added by gstrauss about 3 years ago
ah. The syntax proxy = ()
sets a variable named proxy
, which is legal syntax, though not what you intended. A warning would be issued for proxy.typo = ()