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