Update Docker configuration and Nginx settings to use a new image and improve caching logic

This commit is contained in:
2026-01-07 20:25:11 +01:00
parent 1a641cbdf9
commit 7198a70ec4
3 changed files with 54 additions and 34 deletions

View File

@@ -23,12 +23,17 @@ The nginx configuration implements an inverted caching logic:
## Usage
```bash
# Normal request - NOT cached (default)
curl http://localhost:3000/?url=https://api.example.com/data
Both URL formats are supported:
# Cached request - add the header
curl -H "X-Cache: 1" http://localhost:3000/?url=https://api.example.com/data
```bash
# Path-based URL format (recommended)
curl http://localhost:3001/https://api.example.com/data
# Query parameter format (legacy)
curl "http://localhost:3001/?url=https://api.example.com/data"
# Enable caching with X-Cache header
curl -H "X-Cache: 1" http://localhost:3001/https://api.example.com/data
```
## Features

View File

@@ -1,15 +1,10 @@
version: '3.8'
services:
nginx-cache-proxy:
image: docker.site.quack-lab.dev/nginx-cache-proxy:latest
expose:
- 3000
# image: docker.site.quack-lab.dev/nginx-cache-proxy:latest
image: nginx:alpine
ports:
- "3001:3001"
volumes:
- ./nginx_cache:/var/cache/nginx
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:3000/health || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx-data:/etc/nginx/data
restart: unless-stopped

View File

@@ -1,26 +1,46 @@
events {
worker_connections 1024;
}
http {
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=api_cache:10m max_size=1g inactive=365d;
client_body_temp_path /etc/nginx/data/temp;
proxy_temp_path /etc/nginx/data/temp;
fastcgi_temp_path /etc/nginx/data/temp;
uwsgi_temp_path /etc/nginx/data/temp;
scgi_temp_path /etc/nginx/data/temp;
proxy_cache_path /etc/nginx/data/cache levels=1:2 keys_zone=api_cache:10m max_size=1g inactive=365d;
error_log /dev/stdout debug;
access_log /dev/stdout;
# Use Docker's internal DNS
resolver 127.0.0.11 valid=10s;
server {
listen 3000;
location /health {
return 200 "healthy\n";
add_header Content-Type text/plain;
}
listen 3001;
location / {
if ($arg_url = "") {
return 400 "Missing url parameter";
}
proxy_pass $arg_url;
proxy_http_version 1.1;
proxy_set_header Host $proxy_host;
proxy_ssl_server_name on;
proxy_cache api_cache;
proxy_cache_valid 200 365d;
# Only cache if X-Cache header is present
proxy_cache_bypass $http_x_cache_inverse;
proxy_no_cache $http_x_cache_inverse;
# Set inverse variable (cache disabled by default)
set $http_x_cache_inverse 1;
if ($http_x_cache) {
set $http_x_cache_inverse 0;
proxy_cache_bypass $http_x_cache_this_inverse;
proxy_no_cache $http_x_cache_this_inverse;
set $http_x_cache_this_inverse 1;
if ($http_x_cache_this) {
set $http_x_cache_this_inverse 0;
}
proxy_cache_key $scheme$proxy_host$uri$is_args$args;
proxy_pass $arg_url;
add_header X-Cache-Status $upstream_cache_status;
add_header X-Cache-Status $upstream_cache_status always;
}
}
}
}