getting 412 precondition failed with ngx_cache_purge when trying to purge cache

lu flag

I am new to this and just started using nginx for my pet projects. now i would like to install and use ngx_cache_purge module from, since it has some cool integrations with wordpress.

here is the docker image i came up with:

FROM nginx:1.18.0

RUN apt update && apt install -y --no-install-recommends  --no-install-suggests \
            wget gcc make zlib1g-dev libpcre3-dev

RUN mkdir -p /home/nginx && cd /home/nginx && \
    wget -qO - | tar zxfv - && \
    wget -qO - | tar zxfv -

RUN cd /home/nginx/nginx-1.18.0 && \
    ./configure --add-dynamic-module=../ngx_cache_purge-2.5.1 --with-compat && \
    make modules && \
    cp objs/ /usr/lib/nginx/modules/ 

here is a sample nginx config:

load_module modules/;

http {
    gzip off;
    gzip_vary off;
    gzip_proxied off;
    gzip_comp_level 6;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2 use_temp_path=off keys_zone=proxycache:256m

    proxy_cache_purge PURGE from;

    server {
        listen *:8008;
        location ~* /purgea(/.*) {
            add_header X-url-match $scheme${request_method}my_proxy_server$1$args always;
            proxy_cache_purge proxycache $scheme${request_method}my_proxy_server$1$args;
            cache_purge_response_type json;

here is confirmation that cache file exists:

root@a65be2e6f69c:/# grep -R -a -E "^KEY:" /var/cache/nginx/proxy_cache/ | grep "jquery.min.js?ver=3.6.0"
/var/cache/nginx/proxy_cache/b/3c/e0ec9b13973d56a5780010cadccc73cb:KEY: httpGETmy_proxy_server/wp-includes/js/jquery/jquery.min.js?ver=3.6.0

here is the request i am making to purge the cache for that uri:

root@a65be2e6f69c:/# curl -v localhost:8008/purgea/wp-includes/js/jquery/jquery.min.js?ver=3.6.0
> GET /purgea/wp-includes/js/jquery/jquery.min.js?ver=3.6.0 HTTP/1.1
> Host: localhost:8008
> User-Agent: curl/7.64.0
> Accept: */*
< HTTP/1.1 412 Precondition Failed
< Server: nginx
< Date: Fri, 13 May 2022 01:04:17 GMT
< Content-Type: text/html; charset=UTF-8
< Content-Length: 166
< Connection: keep-alive
< X-url-match: httpGETmy_proxy_server/wp-includes/js/jquery/jquery.min.jsver=3.6.0
<head><title>412 Precondition Failed</title></head>
<center><h1>412 Precondition Failed</h1></center>
* Connection #0 to host localhost left intact

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.