diff --git a/Dockerfile b/Dockerfile index 968b97d..cf593ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ FROM nginx:alpine -# Copy nginx configuration +# Copy nginx configuration and HTML COPY nginx.conf /etc/nginx/nginx.conf +COPY index.html /usr/share/nginx/html/index.html # Create data directories RUN mkdir -p /etc/nginx/data/cache /etc/nginx/data/temp && \ diff --git a/README.md b/README.md index c7faffa..53ac158 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,12 @@ # Nginx Cache Proxy -An nginx proxy server that caches requests only when explicitly requested via the `X-Cache: 1` header. +Navigate to `http://localhost:3000/` for interactive usage with URL builder. ## Quick Start ```bash -# Build the image -./build.sh - -# Run with docker-compose (uses the built image) -docker-compose up +# Build and run +./build.sh && docker-compose up # Or run directly docker run -p 3000:3000 docker.site.quack-lab.dev/nginx-cache-proxy:latest @@ -20,19 +17,24 @@ docker run -p 3000:3000 docker.site.quack-lab.dev/nginx-cache-proxy:latest ```bash # Proxy and cache any URL curl "http://localhost:3000/?url=https://api.example.com/data" + +# Skip cache for this request +curl -H "X-NoCache: 1" "http://localhost:3000/?url=https://api.example.com/data" + +# Cache custom status codes (e.g., 400s) +curl -H "X-Status: 400" "http://localhost:3000/?url=https://api.example.com/bad" + +# Purge cache for specific URL +curl "http://localhost:3000/purge/?url=https://api.example.com/data" ``` ## Features -- **Always caches** all proxied requests -- Cache path: `/etc/nginx/data/cache` -- Cache zone: `api_cache` (10MB memory) -- Max cache size: 100GB -- Cache validity: 365 days for 200 responses -- Max request size: 128MB -- Cache status header: `X-Cache-Status` shows cache hit/miss status -- HTTPS support with proper SSL/TLS headers - -## In n8n - -Add the `X-Cache: 1` header only to requests you want cached. All other requests will bypass the cache completely. +- **Always caches** 2xx status codes for 1 year +- Cache size: 100GB max +- Request size: 128MB max +- X-Cache-Status header shows cache status +- X-NoCache header bypasses cache +- X-Status header caches custom status codes +- Interactive web interface at root path +- Cache purge endpoint diff --git a/index.html b/index.html new file mode 100644 index 0000000..70a6bea --- /dev/null +++ b/index.html @@ -0,0 +1,89 @@ + + + + Nginx Cache Proxy + + + +

Nginx Cache Proxy

+

Proxy and cache any HTTP/HTTPS URL with automatic caching.

+ +
+

Quick URL Builder

+ + +
+
+ +

Usage

+ +
+

Basic Proxy

+
curl "http://localhost:3000/?url=https://api.example.com/data"
+
+ +
+

Skip Cache

+
curl -H "X-NoCache: 1" "http://localhost:3000/?url=https://api.example.com/data"
+
+ +
+

Cache Custom Status Codes

+
curl -H "X-Status: 400" "http://localhost:3000/?url=https://api.example.com/bad"
+
+ +
+

Purge Cache

+
curl "http://localhost:3000/purge/?url=https://api.example.com/data"
+
+ +

Features

+ + + + + diff --git a/nginx.conf b/nginx.conf index d68e103..4906626 100644 --- a/nginx.conf +++ b/nginx.conf @@ -20,8 +20,9 @@ http { listen 3000; location / { + # If no url parameter, serve the readme if ($arg_url = "") { - return 400 "Missing url parameter"; + rewrite ^ /index.html last; } proxy_pass $arg_url; @@ -30,26 +31,16 @@ http { proxy_ssl_server_name on; proxy_cache api_cache; + proxy_cache_valid 200 201 202 203 204 205 206 207 208 226 365d; - # Cache 2xx by default, or status codes from X-Status header - proxy_cache_valid 200 201 202 203 204 206 365d; - - # If X-Status header is present, cache those status codes instead - set $cache_status $http_x_status; - if ($cache_status != "") { - proxy_cache_valid $cache_status 365d; - } - - # Bypass cache if X-NoCache header is present proxy_cache_bypass $http_x_nocache; proxy_no_cache $http_x_nocache; add_header X-Cache-Status $upstream_cache_status always; } - # Cache purge endpoint - location ~ /purge(/.*) { - proxy_cache_purge api_cache $1; + location = /index.html { + root /usr/share/nginx/html; } } } \ No newline at end of file