Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


ngx.exec and ngx.redirect #48

stunti opened this Issue · 14 comments

2 participants


I have a dev server which is ubuntu 10.10 64 bits.
I have installed nginx 1.0.5 with lua-nginx-module and lua-redis-parser.

I have the same setup on another dev server which run centos 5.4.

On both server I run this piece of lua code.

content = ngx.location.capture("/content", {args = ngx.var.args});
if content.status == 302 or content.status == 301 then
-- ngx.redirect(content.header["Location"], content.status);

The url contained in content.header["Location'] is like "/user/redirect?test=1"
On the first server, it run without problem when ngx.redirect() is used but created a "400 Bad Request" when ngx.exec() is used
On the second server, ngx.redirect() create a "400 Bad Request" and hang when ngx.exec() is used.

In both case I use the latest version of nginx and lua-nginx-module from git.

Any way I can figured out why the behavior is different and why it doesn't work overall?

Thanks for your help.


Also, your "nginx -V" output may also be useful to me ;)



I ll start with the easiest: nginx -V

nginx: nginx version: nginx/1.0.5
nginx: built by gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
nginx: configure arguments: --add-module=../lua-nginx-module/deps/ngx_devel_kit --add-module=../set-misc-nginx-module >--add-module=../lua-nginx-module --add-module=../redis2-nginx-module --prefix=/opt/nginx/105 --with-debug


I can't replicate any of these issues with a really simple example.
That mean there is probably multiple problems which cause that. What's trouble me the most the the ngx.redirect causing a 400 bad request because that' what I need. not an internal redirection.
The redirect is done (I can see it in the log and the url in the browser is the new one)
and I can reload the page in the browser and everything works. I don't see anything related to the bad request either in the log. I have debug enabled.
you can see the interesting part of the log here:

The original url is /user/login redirecting to /user/register-business-info?inc=1


Please ensure you're indeed using the latest ngx_lua. There used to be bugs with ngx.redirect/ngx.exec, which were fixed in June or so.


I do have access to that server.

I tried with and various url (https, parameters)
Everytime it works but if I try any local url (relative or absolute) I get the 400.

I am pretty sure I use the latest one since I got it this morning (I also tried with 2.1rc4 but same result)
Is there a way to check?
Is it possible that it's related to the use of a not standard port? 9090


Can you try disabling the keepalive setting in your nginx instance?


I mean setting "keepalive_timeout 0;" in your nginx.conf :)


Yep, that did it.
I tried a few time with and without it. Every time, when keekalive_timeout is at 0, the redirection works.
I ll live it at 0 for now.
Thanks for your help. Feel free to close it if you want.


Could you please show me the complete nginx.conf to me? (Sensible info could be removed, of course) I'd fix it when keepalive is enabled :)


I have removed some path and other ports.
I am a total beginner in lua (so any mistakes is possible)
The point is to recreate some kind of ESI behavior using redis as a cache for the page with some dynamic part following ESI tags.
Let me know if you have any questions


Could you try out the latest version of ngx_lua to see if the issue still exists with http keepalive on?


Consider it resolved.

@agentzh agentzh closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.