October 08, 2015 06:36AM
Спасибо большое! Не догадался, что кеш работает, а заголовок не пишет.

add_header X-Cached $upstream_cache_status always; начало вставлять
заголовок и в 400е ответы.

HTTP/1.1 400 Bad Request
Server: nginx
Date: Thu, 08 Oct 2015 10:29:40 GMT
Content-Length: 0
Connection: keep-alive
*X-Cached: HIT*

2015-10-08 13:21 GMT+03:00 Sergey Kandaurov <pluknet@nginx.com>:

> On Oct 8, 2015, at 12:09 PM, Juriy Strashnov <juriy.foboss@gmail.com>
> wrote:
> > Коллеги, всем привет!
> >
> > Возникла нужда кратковременно кешировать ответы backend'a. Проблема в
> том, что надо не только код 200, но и 400.
> >
> > Попробовал так (в лоб):
> >
> > proxy_cache_path /var/cache/nginx/apicache levels=1:2
> keys_zone=apicache:10m;
> >
> > location /api {
> > <...>
> >
> > proxy_cache apicache;
> > proxy_cache_use_stale error timeout updating;
> > proxy_cache_lock on;
> > proxy_cache_valid any 30s;
> > proxy_cache_valid 400 30s;
> > proxy_cache_methods POST;
> > proxy_cache_key "$request_uri|$request_body";
> >
> > proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
> >
> > add_header X-Cached $upstream_cache_status;
> > }
> >
> > Не помогло! Если на код 200 в ответе появляется заголовок:
> >
> > HTTP/1.1 200 OK
> > Server: nginx
> > Date: Thu, 08 Oct 2015 08:54:38 GMT
> > Content-Length: 0
> > Connection: keep-alive
> > X-Cached: HIT
> >
> > то на 400 его уже нет:
>
> Используйте параметр always, подробности тут:
> http://nginx.org/r/add_header/ru
>
> См. также debug log на предмет сообщений “file cache send”.
>
> --
> Sergey Kandaurov
>
> _______________________________________________
> nginx-ru mailing list
> nginx-ru@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-ru




--
Best regards, Juriy Strashnov

Mob. +7 (953) 742-1550
E-mail: j.strashnov@me.com

Please consider the environment before printing this email.
_______________________________________________
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru
Subject Author Posted

"proxy_cache_valid 400" -- возможно ли?

foboss October 08, 2015 05:10AM

Re: "proxy_cache_valid 400" -- возможно ли?

Sergey Kandaurov October 08, 2015 06:22AM

Re: "proxy_cache_valid 400" -- возможно ли?

foboss October 08, 2015 06:36AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 129
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