0

I have multiple proxy_cache_path directives and in the http block and I want to pass the value of the proxy_cache variable to a lua modul. However, I do not want to define the route (/tmp/cache/BackendA or /tmp/cache/BackendB, etc) more than once. I would rather store it in a variable.

My config snippet:

http {
    proxy_cache_path /tmp/cache/BackendA keys_zone=BACKEND_A_PROXYCACHE:50m max_size=1g use_temp_path=off inactive=20m;
    proxy_cache_path /tmp/cache/BackendB keys_zone=BACKEND_B_PROXYCACHE:100m max_size=2g use_temp_path=off inactive=30m;
    # ...

    server {
        # ...

        location =/BackendA/ServiceA {
            # ...
            proxy_cache BACKEND_A_PROXYCACHE;
            # set $cache_folder_path "/tmp/cache/BackendA";
            set $cache_folder_path $proxy_cache;
            proxy_cache_bypass $cache_folder_path;
        }
        
        location =/BackendB/ServiceB {
            # ...
            proxy_cache BACKEND_B_PROXYCACHE;
            # set $cache_folder_path "/tmp/cache/BackendA";
            set $cache_folder_path $proxy_cache;
            proxy_cache_bypass $cache_folder_path;
        }
    }
}

If i try to use set $cache_folder_path $proxy_cache; command then i can't start the nginx server.

Error message:

nginx: [emerg] unknown "proxy_cache" variable

I'm looking for a more elegant solution than the commented part: set $cache_folder_path "/tmp/cache/BackendA";

The question is what should I do now? Will be grateful for any help.

Milky
  • 143
  • 4
  • 15

1 Answers1

0

if you using Linux and if is support apt-get, for cache module

apt-get install nginx-extras
dılo sürücü
  • 3,821
  • 1
  • 26
  • 28