I am using Nginx to cache some responses. The backend that generates these responses, sets a common Cache-control
header for all the responses. However, I need to cache some of the responses for a longer duration than the others. That is I need to modify the cache-control
header before it is taken into consideration by the proxy_pass
directive.
I am using the ngx_lua_module
and want to modify the Cache-Control
header in the internal
location block using header_filter_by_lua_block
directive. The intended config looks like the following:
location / {
proxy_pass /actual;
proxy_cache something;
}
location = /actual {
internal;
proxy_pass https://backend;
proxy_cache off;
header_filter_by_lua_block {
-- modify cache-control header based on request/response parameters
}
}
However I couldn't figure out a way to achieve this internal redirection via proxy_pass
. I would appreciate any insight you have to make this work.
You cannot
proxy_pass
to a location, you can onlyproxy_pass
to an upstream or an URL (which basically is non-declared upstream). So, answering to your question formally, you shouldproxy_pass
to localhost with Host header set to the currentserver_name
; but this probably will overcomplicate things.Instead - looks like all you need to do is to get rid of the
location / {}
that you don't need and then renamelocation = /actual
tolocation / {}
.I'd also say that you don't need lua at all - just remove the header you're getting from proxied web with
proxy_hide_header
and add your own withadd_header
.