1

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.

1 Answers1

3

You cannot proxy_pass to a location, you can only proxy_pass to an upstream or an URL (which basically is non-declared upstream). So, answering to your question formally, you should proxy_pass to localhost with Host header set to the current server_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 rename location = /actual to location / {}.

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 with add_header.

drookie
  • 8,051
  • 1
  • 17
  • 27