two small questions about embedded perl
Sven 'Darkman' Michels
sven at darkman.de
Wed Dec 15 08:42:54 MSK 2010
Hi,
Am 14.12.2010 23:38, schrieb Igor Sysoev:
> You should "return DECLINED;", in this case nginx will continue to
> process usual handler chain: index, static files, etc.
ok, did that but now i get nothing returned again *sigh*
The log says "GET /file.jpg HTTP/1.0" 0 0 "-" "-"
which is not exactly what i would expect...
the perl module just "return DECLINED;" in this case.
> location ~ \.(png|jpg|gif)$ {
> perl testpackage::handler;
> # do $r->internal_redirect("/new/...");
> }
>
> location /new/ {
> proxy_pass http://internal/;
> }
>
> location / {
> proxy_pass http://internal/;
> }
>
>
ok, this is what i have done now:
location ~ \.(png|jpg|gif)$ {
perl testpackage::handler;
}
location /intredirremoved/ {
rewrite ^/intredirremoved/(.+)$ $1 last;
proxy_pass http://internal/;
proxy_set_header Host $host;
proxy_cache STATIC;
proxy_cache_valid 200 1d;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
}
location / {
proxy_pass http://internal/;
proxy_set_header Host $host;
proxy_cache STATIC;
proxy_cache_valid 200 1d;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
}
maybe its some extra work now, but my module should remove old parts of the
uri. I now add this intredirremoved to get a new location as suggested, but
have to remove it again before passing it to the proxy. "Should" work, but
is probably not the best. Anyway, the config doesn't work at all. I'll post
some more of the module:
#!/usr/bin/perl -w
package testpackage;
use nginx;
sub handler {
$r = shift;
if(($r->uri=~m%^/oldstuff/(.+\.(jpg|png|gif))$%) &&
$r->uri!~m%^/intredirremoved/$%)) {
$file = $1;
$r->internal_redirect("/intredirremoved/$file");
# return OK
# return DECLINED;
} else {
return DECLINED;
}
}
this is what it basicly does, except that the real module is a bit more
complex, not just doing some rewrites. As you can see, i tried with returning
ok, declined, nothing, but nothing worked.
Regards,
Sven
More information about the nginx
mailing list