Welcome! Log In Create A New Profile

Advanced

Re: sending 404 responses for epty objects.

Maxim Dounin
May 04, 2015 10:28AM
Hello!

On Mon, May 04, 2015 at 07:52:46AM -0400, philipp wrote:

> 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;

Removing proxy_cache_bypass should fix things for you.

The problem is that proxy_cache_bypass will be evaluated before a
request is sent to upstream and therefore before
$upstream_http_content_length will be available. As a result
$flag_cache_empty will be always 0. And, because map results are
cached for entire request lifetime, proxy_no_cache will see the
same value, 0.

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
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: 259
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