September 03, 2013 08:52AM
I'm using ngnix as proxy server. There is a situation when backend server is down and I know about it. Thus I'm adding 'Check-Cache' header to request and what I want to do is get the file when it is in cache, and when it is not just return error page. I don't want to pass the request to the backend.

Scenario

$ curl -s -o /dev/null -w "%{http_code}" 0/images/2.jpg -H'Host: example.com'
200
$ pkill -9 backend_server
$ curl -s -o /dev/null -w "%{http_code}" 0/images/2.jpg -H'Host: example.com' -H'Check-Cache: true'
404 <-- I want to 200 here

nginx.conf

server {
listen 80;

underscores_in_headers on;
proxy_cache_purge on;

location / {
error_page 599 = @jail;
recursive_error_pages on;

if ($http_check_cache = "true") {
return 599;
}

proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_cache my-cache;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
proxy_cache_key $uri$is_args$args;
}

location @jail {
# try_files ??
# proxy_cache_key (If i can get it i can use try_files)
# what other solution...
return 404;
}
}
Subject Author Posted

Return file when it's in cache/check if file exists in cache

ixos September 03, 2013 08:52AM

Re: Return file when it's in cache/check if file exists in cache

ixos September 06, 2013 04:48AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 171
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready