Welcome! Log In Create A New Profile

Advanced

proxy_cache_background_update ignores regular expression match when updating

Richard Stanway via nginx
December 04, 2018 12:58PM
Hello,
I'm running into an issue where a proxied location with a regular
expression match does not correctly update the cache when using
proxy_cache_background_update. The update request to the backend seems
to be missing the captured parameters from the regex. I've created a
small test case that demonstrates this in nginx 1.15.7. Hopefully I'm
not missing anything, I checked the docs and didn't seem to find
anything that would explain this behavior.

nginx version: nginx/1.15.7
built by gcc 6.3.0 20170516 (Debian 6.3.0-18+deb9u1)
built with OpenSSL 1.1.0f 25 May 2017 (running with OpenSSL 1.1.0j
20 Nov 2018)
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx
--modules-path=/usr/lib/nginx/modules
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx
--group=nginx --with-compat --with-file-aio --with-threads
--with-http_addition_module --with-http_auth_request_module
--with-http_dav_module --with-http_flv_module
--with-http_gunzip_module --with-http_gzip_static_module
--with-http_mp4_module --with-http_random_index_module
--with-http_realip_module --with-http_secure_link_module
--with-http_slice_module --with-http_ssl_module
--with-http_stub_status_module --with-http_sub_module
--with-http_v2_module --with-mail --with-mail_ssl_module --with-stream
--with-stream_realip_module --with-stream_ssl_module
--with-stream_ssl_preread_module --with-cc-opt='-g -O2
-fdebug-prefix-map=/data/builder/debuild/nginx-1.15.7/debian/debuild-base/nginx-1.15.7=.
-specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong
-Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC'
--with-ld-opt='-specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro
-Wl,-z,now -Wl,--as-needed -pie'

Configuration:

proxy_cache_path /tmp keys_zone=test:1m max_size=1g inactive=1h
use_temp_path=off;

server {
listen 127.0.0.1:8010;
root /tmp/nginx;
}

server {
listen 127.0.0.1:8011;

location ~ /test/(regular|expression)$ {
proxy_pass http://127.0.0.1:8010/test/$1;
proxy_cache test;
proxy_cache_background_update on;
proxy_cache_use_stale updating;
proxy_cache_valid 10s;
}
}

Initial testing with proxy_cache_background_update off. Log excerpts
show requests to both servers.

First request (one to frontend, one to backend as expected):
127.0.0.1 - - [04/Dec/2018:17:42:31 +0000] "GET /test/regular
HTTP/1.0" 200 8 "-" "curl/7.52.1" "-"
127.0.0.1 - - [04/Dec/2018:17:42:31 +0000] "GET /test/regular
HTTP/1.1" 200 8 "-" "curl/7.52.1" "-"

Second request (served from frontend cache, all good):
127.0.0.1 - - [04/Dec/2018:17:42:35 +0000] "GET /test/regular
HTTP/1.1" 200 8 "-" "curl/7.52.1" "-"

Third request (cache expired, so a new request to backend, also good):
127.0.0.1 - - [04/Dec/2018:17:43:14 +0000] "GET /test/regular
HTTP/1.0" 200 8 "-" "curl/7.52.1" "-"
127.0.0.1 - - [04/Dec/2018:17:43:14 +0000] "GET /test/regular
HTTP/1.1" 200 8 "-" "curl/7.52.1" "-"

After setting proxy_cache_background_update on, every request tries to
do a background update with the wrong URL once the content is expired.
The stale content is still served in the meantime.
127.0.0.1 - - [04/Dec/2018:17:44:01 +0000] "GET /test/ HTTP/1.0" 403
153 "-" "curl/7.52.1" "-"
127.0.0.1 - - [04/Dec/2018:17:44:01 +0000] "GET /test/regular
HTTP/1.1" 200 8 "-" "curl/7.52.1" "-"

127.0.0.1 - - [04/Dec/2018:17:44:15 +0000] "GET /test/ HTTP/1.0" 403
153 "-" "curl/7.52.1" "-"
127.0.0.1 - - [04/Dec/2018:17:44:15 +0000] "GET /test/regular
HTTP/1.1" 200 8 "-" "curl/7.52.1" "-"

127.0.0.1 - - [04/Dec/2018:17:44:17 +0000] "GET /test/ HTTP/1.0" 403
153 "-" "curl/7.52.1" "-"
127.0.0.1 - - [04/Dec/2018:17:44:17 +0000] "GET /test/regular
HTTP/1.1" 200 8 "-" "curl/7.52.1" "-"

127.0.0.1 - - [04/Dec/2018:17:44:19 +0000] "GET /test/ HTTP/1.0" 403
153 "-" "curl/7.52.1" "-"
127.0.0.1 - - [04/Dec/2018:17:44:19 +0000] "GET /test/regular
HTTP/1.1" 200 8 "-" "curl/7.52.1" "-"

127.0.0.1 - - [04/Dec/2018:17:44:21 +0000] "GET /test/ HTTP/1.0" 403
153 "-" "curl/7.52.1" "-"
127.0.0.1 - - [04/Dec/2018:17:44:21 +0000] "GET /test/regular
HTTP/1.1" 200 8 "-" "curl/7.52.1" "-"

Is this a bug or am I misunderstanding how this is supposed to work?
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

proxy_cache_background_update ignores regular expression match when updating

Richard Stanway via nginx December 04, 2018 12:58PM

Re: proxy_cache_background_update ignores regular expression match when updating

Roman Arutyunyan December 06, 2018 08:02AM

Re: proxy_cache_background_update ignores regular expression match when updating

Roman Arutyunyan December 06, 2018 01:04PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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