two small questions about embedded perl

Igor Sysoev igor at sysoev.ru
Wed Dec 15 00:59:32 MSK 2010


On Tue, Dec 14, 2010 at 10:36:31PM +0100, Sven 'Darkman' Michels wrote:

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

Try

-      proxy_pass  http://backend;
+      proxy_pass  http://backend/;


-- 
Igor Sysoev
http://sysoev.ru/en/



More information about the nginx mailing list