Modifying upstream Vary response header with header_filter_by_lua_file to affect proxy_cache

142 views
Skip to first unread message

Gryzli

unread,
Feb 24, 2017, 9:25:42 AM2/24/17
to openresty-en
Hello, 

Firstable, thanks for maintaining such great modules ! 

What I'm trying to accomplish is the following: 

1) I use Nginx as caching proxy to Apache 
(using the proxy_cache directive)
- Nginx version: 1.11.8
- Lua-nginx-module: 0.10.7

2) I want Nginx to process Vary header, and be compatible with it as it does by default
(I want him to cache different content based on upstream Vary response header)

3) Sometimes I want to modify the "Vary:" header which is comming from upstream, and remove some header from it (for example User-Agent)

This I'm trying to do with lua-nginx-module (header_filter_by_lua_file)


4) My (shortened) Nginx config looks something like  that: 

location "/content/" {
        # -----------------
        # This is the actual caching config 
        # -------------------
        # Try to manipulate vary header 
        # This script reads "Vary:" header, and removes "User-Agent" from it 
        header_filter_by_lua_file "/usr/local/nginx/lua/cache_proxy_key.lua"; 

        proxy_cache gryzli.info_4001d4e58d3dd1fe16b6adf3339bf05a;
        proxy_cache_bypass $cookie_nocache $arg_nocache $no_cache;
        proxy_cache_valid 15m; 
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass $apache_url ; 

        add_header X-Cache-Status $upstream_cache_status;
        add_header X-Cache-Disabled v_$no_cache;

}



The problem is that proxy_cache somehow sees the original "Vary:" header (which contains User-Agent), and continues to store different cache for different user-agents. 

In my "cache_proxy_key.lua" , I'm getting the Vary: header, remove User-Agent, and store it back with something like: 
ngx.header.Vary = vary_header_without_user_agent ; 

Do you have any suggestions, why this would not work as I expect, and maybe how can I achieve such thing ? 

Thanks in advance ! 

ytl m

unread,
Feb 27, 2017, 10:49:05 PM2/27/17
to openresty-en
I think proxy_cache_key may be helpful.

在 2017年2月24日星期五 UTC+8下午10:25:42,Gryzli写道:

Gryzli

unread,
Mar 13, 2017, 4:51:12 AM3/13/17
to openresty-en
Could you be more specific, how exact proxy_cache_key could help in this case ? 
Reply all
Reply to author
Forward
0 new messages