two small questions about embedded perl

Sven 'Darkman' Michels sven at darkman.de
Wed Dec 15 00:36:31 MSK 2010


Hi there,

i just got two small questions about using embedded perl:
first: i would like to "rewrite" the request using a perl module, since the
rewrite is a bit more than just regexp. I thought that using "internal_redirect"
is the right way to do, but i don't get working.
The module looks like:
package testpackage;
use nginx;
use ...;

sub handler {
	$r = shift;
	.. some stuff
	if($ok) {
		$r->internal_redirect("/$uri");
		return OK;
	}
}

i tried with and without return, seems to make no difference...

nginx config looks like:
...
http {
	perl_require module.pm;
...
	server {
		...
		location /folder {
			perl testpackage::handler;
			# proxy_pass stuff
		}
		location / {
			proxy_pass stuff
		}
	}
}

i did put some proxy stuff into the location /folder, after the module, and
some into location /, but the best i got was a unedited call to the backend.
The module itself got called, usually i get nothing returned (state 200 but
no data). If i return other codes in the module, they work as expected. So
the module itself is working, just the rewrite/proxy stuff isn't.

Next question: is it possible to pass vars to the module? like having a special
option per location which is passed to the module instead of using a couple
of modules...

Thanks and regards,
Sven



More information about the nginx mailing list