Using proxy_cache_background_update

jeanpaul nginx-forum at
Sun Feb 26 18:08:02 UTC 2017

Hi Maxim,

I stripped down my configuration and removed 'unneeded' parts to reproduce.

I'm able to reproduce it with the following settings:

    location / {
     # Added to mitigate the issue. Removed for testing
     #rewrite ^/index.html$ / break;

     proxy_pass  http://backends;
     proxy_next_upstream error timeout invalid_header;
     proxy_buffering on;
     proxy_connect_timeout 1;
     proxy_read_timeout 30;
     proxy_cache_background_update on;

     proxy_http_version 1.1;
     proxy_set_header Connection "";

     proxy_cache            STATIC;
     proxy_cache_use_stale  error timeout invalid_header updating http_500
http_502 http_503 http_504;
     proxy_set_header        Host            $host;
     proxy_set_header        X-Real-IP       $remote_addr;
     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header        Accept-Encoding  "";

     set $no_cache "";

     proxy_ignore_headers    Cache-Control Expires Vary;

     # Removing the if construction and leaving the "expires" in place
solves the issue!
     if ($no_cache = "") {
       expires               1s;

     proxy_cache_valid 200   3s;

To test the call I used curl and wget:
curl --verbose --header "host:" -o /dev/null
wget --header "host:" --output-document=/dev/null

The Apache logs show: - - [26/Feb/2017:18:49:17 +0100] "GET
/index.html HTTP/1.1" 404 43193 "-" "curl/7.26.0" - - [26/Feb/2017:18:53:22 +0100] "GET
/index.html HTTP/1.1" 404 43194 "-" "Wget/1.13.4 (linux-gnu)"

I captured traffic using tcpdump and Wireshark shows the following:

Original request with curl

GET / HTTP/1.1
User-Agent: curl/7.26.0
Accept: */*

Resulting request from Nginx:

GET /index.html HTTP/1.1
User-Agent: curl/7.26.0
Accept: */*

HTTP/1.1 404 Not Found
Date: Sun, 26 Feb 2017 18:04:24 GMT
Server: Apache

Thanks in advance,


Posted at Nginx Forum:,272622,272629#msg-272629

More information about the nginx mailing list