openresty / lua-resty-redis

Lua redis client driver for the ngx_lua based on the cosocket API
1.91k stars 448 forks source link

Main request hangs with multiple SSI subrequests #39

Open frozenminds opened 10 years ago

frozenminds commented 10 years ago

Hello,

After reading the issue #23 I have updated my configuration to the following: https://gist.github.com/frozenminds/5a1f0b9047c7af69ec61

Each SSI request will try to get the content from Redis, if key is not saved in cache yet, it will fallback to a PHP route which will generate the content, save it to Redis and return the output. The second time, Nginx will retrieve the content from Redis because it was cached.

On a page I have 4 SSI calls. The last one hangs on the very first request before the page is also stored in Nginx's FastCgi cache.

<!-- include virtual="/ssi?action=a -->
<!-- include virtual="/ssi?action=b -->
<!-- include virtual="/ssi?action=c&product_id=123 -->
<!-- include virtual="/ssi?action=c&category_id=999 -->

I am aware of this: http://wiki.nginx.org/HttpLuaModule#Mixing_with_SSI_Not_Supported But what I do not understand, do I have to completely turn off the SSI module and write my own module that will parse the SSI tags () and then use ngx.location.capture or _ngx.location.capturemulti the get the content?

If I do have to parse the SSI tags, do you have any idea where do I start from? Could you please guide me further?

Thank you in advance! Boby

agentzh commented 10 years ago

@frozenminds You don't have to remove ngx_ssi from your nginx build. You just need to avoid mixing ngx_ssi's configurations with ngx_lua's in the same main request.

What do you have in your conf.d/server/fastcgi_params.conf file? And what versions of ngx_lua and nginx are using? Are you using my openresty bundle?

BTW, please avoid using the word "ssi" in your configurations where ngx_ssi is not used at all. That is very confusing.

frozenminds commented 10 years ago

Hi @agentzh ,

First of all thank you for the quick reply.

I am using ngx_openresty-1.5.8.1, seems like the latest. Also tried with ngx_openresty-1.4.3.6. Added now also the fastcgi_params.conf file to my Gist: https://gist.github.com/frozenminds/5a1f0b9047c7af69ec61#file-fastcgi_params-conf

I do have in my main request some small Lua's: set_by_lua_file, rewrite_by_lua_file and header_filter_by_lua_file. None of them is making any other sub-request or big stuff. Just very basic IF/ELSE.

Thank you!

agentzh commented 10 years ago

@frozenminds Thank you for the info! I have several suggestions for you:

  1. Please try creating a minimal but still complete example that can reproduce the issue. It'll be trivial for me to analyze the issue if I can reproduce it on my side :) You'd better use ngx_proxy instead of ngx_fastcgi if you can in your minimal test case because I don't want to run a fastcgi backend to run your example, which is quite a burden for me.
  2. Failing that, please enable nginx's debug logging in your openresty build (by specifying --with-debug for ./configure and use the debug level in your error_log directive) and provide all the debug logs for the problematic request. See also http://nginx.org/en/docs/debugging_log.html

Thanks!

frozenminds commented 10 years ago

@agentzh I will try to create an example for you. Hopefully tomorrow.

Thank you very much!

frozenminds commented 10 years ago

Still haven't finished the setup :( Would you mind to get access via SSH to an already configured server?

Thanks!

agentzh commented 10 years ago

@frozenminds No, I don't mind. Please send me details privately to my email address, agentzh at gmail dot com :)

frozenminds commented 10 years ago

Seems to be something else actually. Will try to fix the code that I suspect and get back to you.

KunkkaCoco commented 8 years ago

I have the same problem!
Could you tell me the Solutions! Thank you @agentzh

agentzh commented 8 years ago

@KunkkaCoco The NGINX SSI module is complicated and error prone. Better use ngx_lua to do the content templating instead. For example, with Lemplate:

https://github.com/openresty/lemplate