From 810cebadd9e9b3d52d002fa31ae7de9faf391a65 Mon Sep 17 00:00:00 2001 From: GRMrGecko Date: Thu, 1 Aug 2024 11:36:53 -0500 Subject: [PATCH] Found that /var/run is deprecated, should use /run. Also added new example usage. --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++---- main.go | 2 +- serverCmd.go | 2 +- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 97455e4..5a58af4 100644 --- a/README.md +++ b/README.md @@ -74,8 +74,9 @@ http { server { location / { + proxy_cache_bypass $is_purge; if ($is_purge) { - proxy_pass http://unix:/var/run/nginx-cache-purge/http.sock; + proxy_pass http://unix:/run/nginx-cache-purge/http.sock; rewrite ^ /?path=/var/nginx/proxy_temp/cache&key=$server_name$request_uri break; } @@ -99,8 +100,9 @@ http { server { location / { + proxy_cache_bypass $is_purge; if ($is_purge) { - proxy_pass http://unix:/var/run/nginx-cache-purge/http.sock; + proxy_pass http://unix:/run/nginx-cache-purge/http.sock; rewrite ^ /?path=/var/nginx/proxy_temp/cache&key=$server_name$request_uri break; } @@ -124,8 +126,45 @@ http { server { location / { + proxy_cache_bypass $is_purge; if ($is_purge) { - proxy_pass http://unix:/var/run/nginx-cache-purge/http.sock; + proxy_pass http://unix:/run/nginx-cache-purge/http.sock; + rewrite ^ /?path=/var/nginx/proxy_temp/cache&key=$server_name$request_uri break; + } + + proxy_cache my_cache; + proxy_pass http://upstream; + } + } +} +``` + +### Auth via header and IP white list. +``` +http { + map $http_purge_token $is_purge { + default 0; + nnCgKUx1p2bIABXR 1; + } + + geo $purge_allowed { + default 0; + 127.0.0.1 1; + 192.168.0.0/24 1; + } + + proxy_cache_path /var/nginx/proxy_temp/cache levels=1:2 keys_zone=my_cache:10m; + proxy_cache_key $server_name$request_uri; + + server { + location / { + set $should_purge $purge_allowed; + if ($is_purge != 1) { + set $should_purge 0; + } + proxy_cache_bypass $should_purge; + if ($should_purge) { + proxy_pass http://unix:/run/nginx-cache-purge/http.sock; rewrite ^ /?path=/var/nginx/proxy_temp/cache&key=$server_name$request_uri break; } @@ -150,7 +189,7 @@ http { location ~ /purge(/.*) { allow 127.0.0.1; deny all; - proxy_pass http://unix:/var/run/nginx-cache-purge/http.sock; + proxy_pass http://unix:/run/nginx-cache-purge/http.sock; rewrite ^ /?path=/var/nginx/proxy_temp/cache&key=$server_name$1 break; } } diff --git a/main.go b/main.go index 54d5178..23d5b40 100644 --- a/main.go +++ b/main.go @@ -18,7 +18,7 @@ import ( const ( serviceName = "nginx-cache-purge" serviceDescription = "Tool to help purge Nginx cache " - serviceVersion = "0.1.2" + serviceVersion = "0.1.3" ) // App structure to access global app variables. diff --git a/serverCmd.go b/serverCmd.go index 8adb11c..dcfee50 100644 --- a/serverCmd.go +++ b/serverCmd.go @@ -51,7 +51,7 @@ func (a *ServerCmd) Run() error { // Determine UNIX socket path. unixSocket := a.Socket if unixSocket == "" { - unixSocket = "/var/run/nginx-cache-purge/http.sock" + unixSocket = "/run/nginx-cache-purge/http.sock" } // If socket exists, remove it.