lighttpd rewrite-once rule isn't working - url-rewriting

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/.

Related

lighttpd redirect and rewrite to internal server

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")

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;

Magento custom shippment method

I wrote shippment module with checking a lot of resources/tutorials etc. I am using magento 1.9. Source of module is:
https://github.com/aleextra/magentoshipping
I lost full day to find why it doesn't works fine. Magento see my module, when I am adding at Model/Carrier.php at line 52 code:
die($result);
it shows objec dump:
Mage_Shipping_Model_Rate_Result Object
(
[_rates:protected] => Array
(
[0] => Mage_Shipping_Model_Rate_Result_Method Object
(
[_data:protected] => Array
(
[carrier] => mikshipping
[carrier_title] => Mik Carrier
[method] => fixed
[method_title] => Fixed price 10
[price] => 10
[cost] => 10.00
)
[_hasDataChanges:protected] => 1
[_origData:protected] =>
[_idFieldName:protected] =>
[_isDeleted:protected] =>
[_oldFieldsMap:protected] => Array
(
)
[_syncFieldsMap:protected] => Array
(
)
)
)
[_error:protected] =>
)
What I am doing wrong?
As a quick guess I say that your carriers name in the config.xml (mshipping) does not match the code used in Carrier.php (mikshipping). I have them always being the same so Iḿ not absolutely sure if this might cause the issue, but it is easy to check.

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

Resources