# Location\_Capture\_By\_Lua and Reverse Proxy Cache

**URL:** <https://www.ruby-forum.com/t/location-capture-by-lua-and-reverse-proxy-cache/236466>\
**Category:** NGINX\
**Created:** [September 5, 2013, 9:45am UTC](https://www.ruby-forum.com/t/location-capture-by-lua-and-reverse-proxy-cache/236466 "2013-09-05T09:45:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [September 5, 2013, 9:45am UTC](https://www.ruby-forum.com/t/location-capture-by-lua-and-reverse-proxy-cache/236466/1 "2013-09-05T09:45:51Z")

</div>

Hi,

Was trying to get hold of the response recieved through upstream server  
or through nginx cache . However found that thier’s no cache hit when  
doing this way .

for brevity just posting the relevant code : looks like for something  
out there through which cache is ignored : also the headers out of  
Passenger\_backed are not returned through the conetnt\_by\_lua stuff.

location / {

content\_by\_lua ’  
local res = ngx.location.capture(  
“/passenger\_backend”,  
{ method = ngx.HTTP\_POST, body = ngx.var.request\_body})  
ngx.header[“X-My-Header”] = “blah blah”  
ngx.log(ngx.CRIT,"Inside Content : " , “hello”)  
ngx.say(res.body)  
';  
}

======

location /passenger\_backend {  
proxy\_pass http://web\_units;  
proxy\_cache small;  
proxy\_cache\_methods POST;  
proxy\_cache\_key “$request\_uri|$request\_body”;  
client\_max\_body\_size 500M;  
open\_file\_cache max=200000 inactive=50s;  
open\_file\_cache\_valid 50s;  
open\_file\_cache\_min\_uses 2;  
open\_file\_cache\_errors on;  
################# Gzip Settings ################  
gzip on;  
gzip\_comp\_level 6;  
gzip\_min\_length 10240;  
gzip\_proxied expired no-cache no-store private auth;  
#gzip\_proxied any;  
#gzip\_static on;  
gzip\_types text/plain text/css application/json application/x-javascript  
text/xml application/xml application/xml+rss text/javascript  
application/javascript text/x-js;  
gzip\_disable “MSIE [1-6].”;  
###################################################

```
    proxy_buffering on;
    proxy_buffers 8 32M;
    proxy_buffer_size 64k;
    proxy_cache_valid 200 302 72h;

```

# proxy\_cache\_valid 404 10m;

```
fastcgi_read_timeout 120s;
fastcgi_send_timeout 120s;
proxy_read_timeout 120s;
proxy_connect_timeout 120s;
proxy_cache_use_stale updating;
add_header X-Cached $upstream_cache_status;
set_real_ip_from 10.86.102.0/24;
real_ip_header X-Forwarded-For;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers Cache-Control;

}
```

---

<div class="post-metadata">

**Author:** ![shubham\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/35a633/32.png) [@shubham\_s](https://www.ruby-forum.com/u/shubham_s)\
**Post date:** [September 5, 2013, 9:29pm UTC](https://www.ruby-forum.com/t/location-capture-by-lua-and-reverse-proxy-cache/236466/2 "2013-09-05T21:29:18Z")

</div>

Hello!

On Thu, Sep 5, 2013 at 12:45 AM, shubham s. wrote:

> Was trying to get hold of the response recieved through upstream server  
> or through nginx cache . However found that thier’s no cache hit when  
> doing this way .
> 
> for brevity just posting the relevant code : looks like for something  
> out there through which cache is ignored : also the headers out of  
> Passenger\_backed are not returned through the conetnt\_by\_lua stuff.

Please check out my (detailed) reply on the openresty-en mailing list:

```
https://groups.google.com/d/msg/openresty-en/MbegSFArHqg/Hs_aMT3YmdsJ

```

I won’t repeat it here 🙂

Regards,  
-agentzh
