Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ngx.exec and ngx.redirect #48

Closed
stunti opened this Issue · 14 comments

2 participants

@stunti

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);
ngx.exec(content.header["Location"]);
end

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

@agentzh
Owner
@agentzh
Owner

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

Regards,
-agentzh

@stunti

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

@stunti

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: https://gist.github.com/1141752

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

@agentzh
Owner
@agentzh
Owner

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.

@stunti

I do have access to that server.

I tried with http://google.com 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

@agentzh
Owner

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

@agentzh
Owner

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

@stunti

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.

@agentzh
Owner

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

@stunti

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
https://gist.github.com/1145681

@agentzh
Owner

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

@agentzh
Owner

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.