Files
lucioandClaude Opus 5.5 e48a1eacf4 Keep hotlink 403s out of CDN and browser caches
The tile hotlink refusal is sent with Cache-Control: no-store from
LuPhoto, Caddy and nginx instead of inheriting the one-year immutable
header. cloudflare.md explains that edge-cached tiles bypass the
origin Referer check, recommends a WAF rule for /t/, and notes that
tile URLs depend only on the photo, the settings and the site key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 22:49:45 -08:00

83 lines
2.8 KiB
Nginx Configuration File

map $http_referer $luphoto_hotlink {
default 1;
"" 0;
"~^https?://photos\.luciochen\.com(:[0-9]+)?(/|$)" 0;
}
map "$request_method $uri" $luphoto_bad_method {
default 1;
"~^(GET|HEAD) " 0;
"POST /k" 0;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name photos.luciochen.com;
ssl_certificate /etc/letsencrypt/live/photos.luciochen.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/photos.luciochen.com/privkey.pem;
root /var/lib/luphoto/site/current;
index index.html;
autoindex off;
disable_symlinks off;
gzip_static on;
server_tokens off;
error_page 404 /404.html;
if ($luphoto_bad_method) {
return 405;
}
location ~ (/\.|\.gz$) {
return 404;
}
location = /k {
client_max_body_size 4k;
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Connection "";
}
location = /404.html {
internal;
add_header Cache-Control "public, max-age=60" always;
add_header Content-Security-Policy "default-src 'self'; img-src 'self' blob: data:; font-src 'self'; worker-src 'self'; frame-ancestors 'none'" always;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
}
location /t/ {
if ($luphoto_hotlink) {
add_header Cache-Control "no-store" always;
return 403;
}
add_header Cache-Control "public, max-age=31536000, immutable" always;
add_header Content-Security-Policy "default-src 'self'; img-src 'self' blob: data:; font-src 'self'; worker-src 'self'; frame-ancestors 'none'" always;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
try_files $uri =404;
}
location ~ ^/(og|assets)/ {
add_header Cache-Control "public, max-age=31536000, immutable" always;
add_header Content-Security-Policy "default-src 'self'; img-src 'self' blob: data:; font-src 'self'; worker-src 'self'; frame-ancestors 'none'" always;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
try_files $uri =404;
}
location / {
add_header Cache-Control "public, max-age=60" always;
add_header Content-Security-Policy "default-src 'self'; img-src 'self' blob: data:; font-src 'self'; worker-src 'self'; frame-ancestors 'none'" always;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
try_files $uri $uri/index.html =404;
}
}