Welcome! Log In Create A New Profile

Advanced

Re: using $upstream* variables inside map directive

Ruslan Ermilov
May 07, 2014 10:40AM
On Wed, May 07, 2014 at 08:53:56AM -0400, Kirill K. wrote:
> Thanks, Ruslan,
> Thing is, I tried to "debug" whether $dontcache is being set at all by
> exposing it via response headers (along with content-length), and it shows
> that $upstream_response_length is ignored by map completely, i.e. no matter
> where I use $dontcache, it will never get any value different from default
> (i.e. 0). Even though $upstream_response_length is validated correctly (and
> can be exposed in headers), the map directive just ignores it.

I tested that your map works when used ONLY in proxy_no_cache,
and it indeed DTRT: responses with content length less than
100 aren't cached.

Here's the config snippet:

: http {
: proxy_cache_path proxy_cache keys_zone=proxy_cache:10m;
:
: map $upstream_http_content_length $dontcache {
: default 0;
: ~^\d\d$ 1;
: ~^\d$ 1;
: }
:
: server {
: listen 8000;
:
: location / {
: proxy_pass http://127.0.0.1:8001;
: proxy_cache proxy_cache;
: proxy_cache_valid 300m;
: proxy_no_cache $dontcache;
:
: add_header X-DontCache $dontcache;
: }
: }
:
: server {
: listen 8001;
:
: return 200 "ok";
: }
: }

$ curl -i http://127.0.0.1:8000/test
HTTP/1.1 200 OK
Server: nginx/1.7.1
Date: Wed, 07 May 2014 14:34:19 GMT
Content-Type: text/plain
Content-Length: 2
Connection: keep-alive
X-DontCache: 1

ok

And there will be no file in "proxy_cache" directory.

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

using $upstream* variables inside map directive

Kirill K. May 07, 2014 01:38AM

Re: using $upstream* variables inside map directive

Jonathan Matthews May 07, 2014 06:32AM

Re: using $upstream* variables inside map directive

Kirill K. May 07, 2014 07:44AM

Re: using $upstream* variables inside map directive

Ruslan Ermilov May 07, 2014 08:46AM

Re: using $upstream* variables inside map directive

Kirill K. May 07, 2014 08:53AM

Re: using $upstream* variables inside map directive

Ruslan Ermilov May 07, 2014 10:40AM

Re: using $upstream* variables inside map directive

Kirill K. May 07, 2014 03:44PM

Re: using $upstream* variables inside map directive

unoobee November 11, 2020 12:55PM

Re: using $upstream* variables inside map directive

ru@nginx.com November 11, 2020 02:14PM

Re: using $upstream* variables inside map directive

unoobee November 12, 2020 02:33AM

Re: using $upstream* variables inside map directive

Francis Daly November 12, 2020 03:36AM

Re: using $upstream* variables inside map directive

unoobee November 12, 2020 04:58AM

Re: using $upstream* variables inside map directive

Francis Daly November 12, 2020 09:36AM

Re: using $upstream* variables inside map directive

unoobee November 12, 2020 11:00AM

Re: using $upstream* variables inside map directive

Francis Daly November 12, 2020 11:50AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 81
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready