Compare commits
No commits in common. "main" and "v0.1.2" have entirely different histories.
48
README.md
48
README.md
@ -44,6 +44,7 @@ After=network.target
|
|||||||
User=nginx
|
User=nginx
|
||||||
Group=nginx
|
Group=nginx
|
||||||
RuntimeDirectory=nginx-cache-purge
|
RuntimeDirectory=nginx-cache-purge
|
||||||
|
PIDFile=/var/run/nginx-cache-purge/service.pid
|
||||||
ExecStart=/usr/local/bin/nginx-cache-purge server
|
ExecStart=/usr/local/bin/nginx-cache-purge server
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=3s
|
RestartSec=3s
|
||||||
@ -74,9 +75,8 @@ http {
|
|||||||
|
|
||||||
server {
|
server {
|
||||||
location / {
|
location / {
|
||||||
proxy_cache_bypass $is_purge;
|
|
||||||
if ($is_purge) {
|
if ($is_purge) {
|
||||||
proxy_pass http://unix:/run/nginx-cache-purge/http.sock;
|
proxy_pass http://unix:/var/run/nginx-cache-purge/http.sock;
|
||||||
rewrite ^ /?path=/var/nginx/proxy_temp/cache&key=$server_name$request_uri break;
|
rewrite ^ /?path=/var/nginx/proxy_temp/cache&key=$server_name$request_uri break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,9 +100,8 @@ http {
|
|||||||
|
|
||||||
server {
|
server {
|
||||||
location / {
|
location / {
|
||||||
proxy_cache_bypass $is_purge;
|
|
||||||
if ($is_purge) {
|
if ($is_purge) {
|
||||||
proxy_pass http://unix:/run/nginx-cache-purge/http.sock;
|
proxy_pass http://unix:/var/run/nginx-cache-purge/http.sock;
|
||||||
rewrite ^ /?path=/var/nginx/proxy_temp/cache&key=$server_name$request_uri break;
|
rewrite ^ /?path=/var/nginx/proxy_temp/cache&key=$server_name$request_uri break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,45 +125,8 @@ http {
|
|||||||
|
|
||||||
server {
|
server {
|
||||||
location / {
|
location / {
|
||||||
proxy_cache_bypass $is_purge;
|
|
||||||
if ($is_purge) {
|
if ($is_purge) {
|
||||||
proxy_pass http://unix:/run/nginx-cache-purge/http.sock;
|
proxy_pass http://unix:/var/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;
|
rewrite ^ /?path=/var/nginx/proxy_temp/cache&key=$server_name$request_uri break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +151,7 @@ http {
|
|||||||
location ~ /purge(/.*) {
|
location ~ /purge(/.*) {
|
||||||
allow 127.0.0.1;
|
allow 127.0.0.1;
|
||||||
deny all;
|
deny all;
|
||||||
proxy_pass http://unix:/run/nginx-cache-purge/http.sock;
|
proxy_pass http://unix:/var/run/nginx-cache-purge/http.sock;
|
||||||
rewrite ^ /?path=/var/nginx/proxy_temp/cache&key=$server_name$1 break;
|
rewrite ^ /?path=/var/nginx/proxy_temp/cache&key=$server_name$1 break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
main.go
4
main.go
@ -18,7 +18,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
serviceName = "nginx-cache-purge"
|
serviceName = "nginx-cache-purge"
|
||||||
serviceDescription = "Tool to help purge Nginx cache "
|
serviceDescription = "Tool to help purge Nginx cache "
|
||||||
serviceVersion = "0.1.4"
|
serviceVersion = "0.1.2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// App structure to access global app variables.
|
// App structure to access global app variables.
|
||||||
@ -43,7 +43,7 @@ func (a *App) PurgeCache(CachePath string, Key string, ExcludeKeys []string) err
|
|||||||
for _, exclude := range ExcludeKeys {
|
for _, exclude := range ExcludeKeys {
|
||||||
if globRegex.MatchString(exclude) {
|
if globRegex.MatchString(exclude) {
|
||||||
g, err := glob.Compile(exclude)
|
g, err := glob.Compile(exclude)
|
||||||
if err == nil && g != nil && g.Match(Key) {
|
if err != nil && g != nil && g.Match(Key) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func (a *ServerCmd) Run() error {
|
|||||||
// Determine UNIX socket path.
|
// Determine UNIX socket path.
|
||||||
unixSocket := a.Socket
|
unixSocket := a.Socket
|
||||||
if unixSocket == "" {
|
if unixSocket == "" {
|
||||||
unixSocket = "/run/nginx-cache-purge/http.sock"
|
unixSocket = "/var/run/nginx-cache-purge/http.sock"
|
||||||
}
|
}
|
||||||
|
|
||||||
// If socket exists, remove it.
|
// If socket exists, remove it.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user