Hallucinate a short little readme on index.html (/)

This commit is contained in:
2026-01-07 21:13:02 +01:00
parent 5e4c9c533e
commit 2ed228b7fb
4 changed files with 116 additions and 33 deletions

View File

@@ -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 && \

View File

@@ -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

89
index.html Normal file
View File

@@ -0,0 +1,89 @@
<!DOCTYPE html>
<html>
<head>
<title>Nginx Cache Proxy</title>
<style>
body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
.usage { background: #f5f5f5; padding: 15px; border-radius: 5px; margin: 10px 0; }
.copy-field { margin: 20px 0; }
input { width: 100%; padding: 10px; font-size: 16px; }
button { background: #007cba; color: white; border: none; padding: 10px 20px; cursor: pointer; }
button:hover { background: #005a87; }
.status { margin-top: 10px; color: green; }
</style>
</head>
<body>
<h1>Nginx Cache Proxy</h1>
<p>Proxy and cache any HTTP/HTTPS URL with automatic caching.</p>
<div class="copy-field">
<h3>Quick URL Builder</h3>
<input type="text" id="urlInput" placeholder="Enter target URL (e.g., https://api.example.com/data)">
<button onclick="copyUrl()">Copy Proxy URL</button>
<div id="status" class="status"></div>
</div>
<h2>Usage</h2>
<div class="usage">
<h3>Basic Proxy</h3>
<pre>curl "http://localhost:3000/?url=https://api.example.com/data"</pre>
</div>
<div class="usage">
<h3>Skip Cache</h3>
<pre>curl -H "X-NoCache: 1" "http://localhost:3000/?url=https://api.example.com/data"</pre>
</div>
<div class="usage">
<h3>Cache Custom Status Codes</h3>
<pre>curl -H "X-Status: 400" "http://localhost:3000/?url=https://api.example.com/bad"</pre>
</div>
<div class="usage">
<h3>Purge Cache</h3>
<pre>curl "http://localhost:3000/purge/?url=https://api.example.com/data"</pre>
</div>
<h2>Features</h2>
<ul>
<li>Always caches 2xx status codes for 1 year</li>
<li>100GB max cache size</li>
<li>128MB max per request</li>
<li>X-Cache-Status header shows hit/miss</li>
<li>X-NoCache header bypasses cache</li>
<li>X-Status header caches custom status codes</li>
<li>Purge endpoint for cache management</li>
</ul>
<script>
function copyUrl() {
const input = document.getElementById('urlInput');
const status = document.getElementById('status');
if (!input.value.trim()) {
status.textContent = 'Please enter a URL first';
status.style.color = 'red';
return;
}
const proxyUrl = window.location.origin + '/?url=' + encodeURIComponent(input.value);
navigator.clipboard.writeText(proxyUrl).then(() => {
status.textContent = 'Proxy URL copied to clipboard!';
status.style.color = 'green';
}).catch(err => {
// Fallback for older browsers
const textArea = document.createElement('textarea');
textArea.value = proxyUrl;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
status.textContent = 'Proxy URL copied to clipboard!';
status.style.color = 'green';
});
}
</script>
</body>
</html>

View File

@@ -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;
}
}
}