Welcome! Log In Create A New Profile

Advanced

Re: Using proxy_cache_background_update

February 26, 2017 01:08PM
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: www.example.com" -o /dev/null http://1.2.3.4/
wget --header "host: www.example.com" --output-document=/dev/null http://1.2.3.4/


The Apache logs show:
example.com 1.2.3.4 127.0.0.1 - - [26/Feb/2017:18:49:17 +0100] "GET /index.html HTTP/1.1" 404 43193 "-" "curl/7.26.0"
example.com 1.2.3.4 127.0.0.1 - - [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: */*
host: www.example.com


Resulting request from Nginx:

GET /index.html HTTP/1.1
Host: www.example.com
X-Real-IP: 1.2.3.4
X-Forwarded-For: 1.2.3.4
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,

JP
Subject Author Posted

Using proxy_cache_background_update

Jean-Paul Hemelaar February 26, 2017 04:46AM

Re: Using proxy_cache_background_update

Maxim Dounin February 26, 2017 08:16AM

Re: Using proxy_cache_background_update

jeanpaul February 26, 2017 01:08PM

Re: Using proxy_cache_background_update

Maxim Dounin February 26, 2017 10:04PM

Re: Using proxy_cache_background_update

jeanpaul February 27, 2017 05:53AM

Re: Using proxy_cache_background_update

Maxim Dounin February 27, 2017 05:52PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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