lighttpd redirect and rewrite to internal server - mod-rewrite

I am attempting to set up a proxy + rewrite with lighttpd.
I am trying to reverse proxy to two separate servers. The first is meant to be at root (192.168.1.198:7000) and the second is meant to be accessed through the /ram/ directory (192.168.1.197:8000). I am using version 1.4.38-1 of lighttpd and do not have the option of upgrading.
The below is the relevant portion of my lighttpd.config, I am hoping someone can point me to my error!
$SERVER["socket"] == ":82" {
url.rewrite-once = ( "^/ram/(.*)$" => "/$1" )
proxy.server = ( "" => (
"" =>
( "host" => "192.168.1.197",
"port" => 8000
)
)
)
}
else $HTTP["host"] == "subdomain.example.com" {
proxy.balance = "hash"
proxy.server = ( "" => ( ( "host" => "192.168.1.198", "port" => 7000 ) ) )
$HTTP["url"] =~ "(^/ram/)" {
proxy.server = ( "" => (
"" =>
( "host" => "127.0.0.1",
"port" => 81
)
)
)
}
}

FYI, I see three backend proxy servers configured, not two.
Also, all requests from a client to port :82 on your server will be handled by the first conditional block. The 'else $HTTP["host"] == "subdomain.example.com"' will never be seen by clients connecting to port :82 on your lighttpd server.
If you want all requests with Host: subdomain.example.com to follow the instructions in that conditional block, then make that section a standalone 'if' rather than an 'else' tacked on to the first condition ($SERVER["socket"] == ":82")

Related

How do i know notification send to firebase or not

i want to send notification to specific android device with laravel-firebase . currently i am following this "brozot/laravel-fcm" so when Sending a Downstream Message to a Device , how do i know notification is send or not . when i test it in my postman it returns
LaravelFCM\Response\DownstreamResponse Object
(
[numberTokensSuccess:protected] => 0
[numberTokensFailure:protected] => 1
[numberTokenModify:protected] => 0
[messageId:protected] =>
[tokensToDelete:protected] => Array
(
[0] => .....
)
[tokensToModify:protected] => Array
(
)
[tokensToRetry:protected] => Array
(
)
[tokensWithError:protected] => Array
(
)
[hasMissingToken:protected] =>
[tokens:LaravelFCM\Response\DownstreamResponse:private] => Array
(
[0] => .....
)
[logEnabled:protected] =>
)
You can see in the response how many messages succeeded or failed. From your own output above:
[numberTokensSuccess:protected] => 0
[numberTokensFailure:protected] => 1
It looks like you tried to send a message to one device, and it failed.

Lighttpd to nginx vhost rewirte rule conversion

I have following lighttpd redirect rules and would need to convert them to nginx:
url.rewrite-once = (
"^/misc(.*)" => "/misc$1",
"^/show_fileupload.php(.*)" => "/show_fileupload.php$1",
"^/flash(.*)" => "/flash$1",
"^/images(.*)" => "/images$1",
"^/css(.*)" => "/css$1",
"^/js(.*)" => "/js$1",
"^/filestore(.*)" => "/filestore$1",
"/(([a-f0-9]{32})/)?(app/(.+?)/)(lang/(\w{2}-\w{2}|\w{2}|)/)?/*([^\?]*)(?:\?(.*))?" => "/$4.php?rs_module_uri=$7&rs_session=$2&rs_app=$4&rs_lang=$6&$8",
"/(([a-f0-9]{32})/)?(app//)?(lang/(\w{2}-\w{2}|\w{2}|)/)?/*([^\?]*)(?:\?(.*))?" => "/main.php?rs_module_uri=$6&rs_session=$2&&rs_lang=$5&$7",
)
How to convert especially the last two lines?
I finally got it to work, it's even not that different:
rewrite "/(([a-f0-9]{32})/)?(app/(.+?)/)(lang/(\w{2}-\w{2}|\w{2}|)/)?/*([^\?]*)(?:\?(.*))?" /$4.php?rs_module_uri=$7&rs_session=$2&rs_app=$4&rs_lang=$6&$8 last;
rewrite "/(([a-f0-9]{32})/)?(app//)?(lang/(\w{2}-\w{2}|\w{2}|)/)?/*([^\?]*)(?:\?(.*))?" /main.php?rs_module_uri=$6&rs_session=$2&&rs_lang=$5&$7 last;

Cannot get url.rewrite and alias.url to play nice together

Current relavent config from lighttpd.conf:
url.rewrite = (
"^/(.*)\.(.+)$" => "$0",
"^/(.+)/?$" => "/index.php/$1",
)
and
alias.url += (
"/xcache/" => "/usr/share/xcache/"
)
I cant get them to work together. From what I understand, the rewrite hijacks the "/xcache/" url thus not triggering the alias.url.
They both work perfectly fine on their own, but cannot get them to work together. Is there a way to exclude certain strings from the url.rewrite expression?
Solved it:
url.rewrite = (
"^/(xcache)/(.*)" => "$0",
"^/(.*)\.(.+)$" => "$0",
"^/(.+)/?$" => "/index.php/$1",
)
alias.url += (
"/xcache/" => "/usr/share/xcache/"
)

how to setup lighttpd for subdirectory mappings?

For the same host name, I want to do mapping like the following
/subdirectory/_different_end_points_.json map to 127.0.0.1:9001
/_different_end_points_.json map to 127.0.0.1:9002
How to do that? per documentation, it's required that the else clause has to match on a condition as well, which drives me nuts (as a beginner on regular expression)
Have you tried something like that:
$HTTP["url"] =~ "^/subdirectory/_different_end_points_.json" {
proxy.server = (
"/" => (("host" => "127.0.0.1", "port" => 9001))
)
}
else $HTTP["url"] =~ "^/_different_end_points_.json" {
proxy.server = (
"/" => (("host" => "127.0.0.1", "port" => 9002))
)
}
That way, you match each url that starts with /subdirectory/_different_end_points_.jso or (in the else) /_different_end_points_.json.
But be sure that your url realy start with the regex! I mean: h*tp://sample.com/subdirectory/_different_end_points_.json and h*tp://sample.com/_different_end_points_.json

lighttpd rewrite-once rule isn't working

I just got some problems serving static files via Lighttpd.
Here's what I would want to do:
www.example.ch is my domain.
If a call comes to www.example.ch/static/.....css
then I want to reroute it and actually serve the file from static.example.ch/files/....css (see my url.rewrite-once rule).
Somehow this just doesn't work. Am I missing something completely?
$HTTP["host"] =~ "(^|\.)example\.ch$" {
fastcgi.server = (
"/django.fcgi" => (
"main" => (
"socket" => env.HOME + "/webqs/webqs.sock",
"check-local" => "disable",
)
),
)
alias.url = (
"/media" => env.HOME + "/webqs/media",
)
url.rewrite-once = (
"^(/media.*)$" => "$1",
"^/favicon\.ico$" => "/media/favicon.ico",
"^(/static.*)$" => "http://static.example.ch/files/$1",
"^(/.*)$" => "/django.fcgi$1",
)
}
Given the regular expression "^(/static.*)$" it looks like $1 is going to contain /static/...css. Is there a static/ directory under your files/ directory? If not, try changing the regular expression to something like:
"^/static/(.*)$"
This should match everything after /static/ but won't also include the string /static/.

Resources