Welcome! Log In Create A New Profile

Advanced

Re: sending 404 responses for epty objects.

May 04, 2015 07:52AM
Hi Maxim,
should this solution work?
http://syshero.org/post/49594172838/avoid-caching-0-byte-files-on-nginx

I have created a simple test setup like:

map $upstream_http_content_length $flag_cache_empty {
default 0;
0 1;
}

server {
listen 127.0.0.1:80;

server_name local;

location /empty {
return 200 "";
}
location /full {
return 200 "full";
}
}

server {
listen 127.0.0.1:80;

server_name cache;

location / {
proxy_pass http://127.0.0.1;
proxy_cache_valid 200 404 1h;
proxy_no_cache $flag_cache_empty;
proxy_cache_bypass $flag_cache_empty;
proxy_set_header Host local;
add_header X-Cache-Status $upstream_cache_status;
add_header X-Cache-Empty $flag_cache_empty;
add_header X-Upstream-Content-Length $upstream_http_content_length;
}
}

But the flag is always 0:
vagrant@nginx-16-centos-64 bin]$ curl -v -H "Host: cache" http://localhost/empty
* About to connect() to localhost port 80 (#0)
* Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /empty HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Accept: */*
> Host: cache
>
< HTTP/1.1 200 OK
< Server: nginx
< Date: Mon, 04 May 2015 11:37:51 GMT
< Content-Type: application/octet-stream
< Content-Length: 0
< Connection: keep-alive
< X-Cache-Status: MISS
< X-Cache-Empty: 0
< X-Upstream-Content-Length: 0
<
* Connection #0 to host localhost left intact
* Closing connection #0
Subject Author Posted

sending 404 responses for epty objects.

Cord Beermann December 11, 2014 03:54AM

Re: sending 404 responses for epty objects.

itpp2012 December 11, 2014 04:40AM

Re: sending 404 responses for epty objects.

Maxim Dounin December 11, 2014 09:32AM

Re: sending 404 responses for epty objects.

philipp May 04, 2015 07:52AM

Re: sending 404 responses for epty objects.

Maxim Dounin May 04, 2015 10:28AM

Re: sending 404 responses for epty objects.

philipp May 04, 2015 10:45AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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