2 Commits

Author SHA1 Message Date
256c14fece Get rid of the header
What was I thinking????????
2026-01-07 20:52:14 +01:00
3b202226a2 Tidy shit up 2026-01-07 20:49:26 +01:00
4 changed files with 14 additions and 33 deletions

View File

@@ -3,9 +3,9 @@ FROM nginx:alpine
# Copy nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf
# Create cache directory
RUN mkdir -p /var/cache/nginx && \
chown nginx:nginx /var/cache/nginx
# Create data directories
RUN mkdir -p /etc/nginx/data/cache /etc/nginx/data/temp && \
chown -R nginx:nginx /etc/nginx/data
# Expose port
EXPOSE 3000

View File

@@ -15,28 +15,21 @@ docker-compose up
docker run -p 3000:3000 docker.site.quack-lab.dev/nginx-cache-proxy:latest
```
## Configuration
The nginx configuration implements an inverted caching logic:
- **Default behavior**: Requests are NOT cached
- **Cached behavior**: Only requests with `X-Cache: 1` header are cached
## Usage
```bash
# Proxy a URL
# Proxy and cache any URL
curl "http://localhost:3000/?url=https://api.example.com/data"
# Enable caching with X-Cache header
curl -H "X-Cache: 1" "http://localhost:3000/?url=https://api.example.com/data"
```
## Features
- Cache path: `/var/cache/nginx`
- Cache zone: `api_cache` (10MB)
- Max cache size: 1GB
- **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

View File

@@ -9,16 +9,11 @@ DOCKER_REPO="docker.site.quack-lab.dev"
IMAGE_NAME="nginx-cache-proxy"
# ============================================================================
# VALIDATE CONFIGURATION
# BUILD PROJECT
# ============================================================================
echo "Validating nginx configuration..."
docker run --rm -v "$(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro" nginx:alpine nginx -t
if [ $? -ne 0 ]; then
echo "Error validating nginx configuration"
exit 1
fi
echo "Building application..."
# No build step needed for nginx
# ============================================================================
# DOCKER BUILD AND TAG

View File

@@ -9,7 +9,7 @@ http {
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;
proxy_cache_path /etc/nginx/data/cache levels=1:2 keys_zone=api_cache:10m max_size=100g inactive=365d;
error_log /dev/stdout debug;
access_log /dev/stdout;
@@ -18,7 +18,7 @@ http {
resolver 127.0.0.11 valid=10s;
server {
listen 3001;
listen 3000;
location / {
if ($arg_url = "") {
@@ -32,13 +32,6 @@ http {
proxy_cache api_cache;
proxy_cache_valid 200 365d;
proxy_cache_bypass $http_x_cache_inverse;
proxy_no_cache $http_x_cache_inverse;
set $http_x_cache_inverse 1;
if ($http_x_cache) {
set $http_x_cache_inverse 0;
}
add_header X-Cache-Status $upstream_cache_status always;
}
}