Uploads skip per-gallery duplicates, checksums can be backfilled, and STORAGE_BACKEND plus sync tooling make switching storage backends safe.
109 lines
4.0 KiB
Plaintext
109 lines
4.0 KiB
Plaintext
# ============================================================
|
|
# Spanglish Community - Photo Gallery API
|
|
# photos.spanglishcommunity.com
|
|
# ============================================================
|
|
|
|
server {
|
|
listen 80;
|
|
server_name photos.spanglishcommunity.com;
|
|
|
|
location /.well-known/acme-challenge/ {
|
|
root /var/www/html;
|
|
}
|
|
|
|
location / {
|
|
return 301 https://photos.spanglishcommunity.com$request_uri;
|
|
}
|
|
}
|
|
|
|
server {
|
|
listen 443 ssl;
|
|
http2 on;
|
|
|
|
server_name photos.spanglishcommunity.com;
|
|
|
|
# Photos can be larger than typical JSON payloads
|
|
client_max_body_size 25m;
|
|
|
|
# SSL
|
|
ssl_certificate /etc/letsencrypt/live/photos.spanglishcommunity.com/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/photos.spanglishcommunity.com/privkey.pem;
|
|
|
|
include /etc/letsencrypt/options-ssl-nginx.conf;
|
|
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
|
|
|
# Security
|
|
add_header X-Frame-Options "DENY" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
|
|
# Logs
|
|
access_log /var/log/nginx/spanglish_photo_access.log;
|
|
error_log /var/log/nginx/spanglish_photo_error.log;
|
|
|
|
# CORS Configuration
|
|
set $cors_origin "";
|
|
if ($http_origin ~* "^https://(www\.)?spanglishcommunity\.com$") {
|
|
set $cors_origin $http_origin;
|
|
}
|
|
|
|
add_header 'Access-Control-Allow-Origin' $cors_origin always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, PATCH, OPTIONS' always;
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
|
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
|
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
|
|
|
|
# Ensure 413 returns JSON + CORS
|
|
error_page 413 = @payload_too_large;
|
|
location @payload_too_large {
|
|
default_type application/json;
|
|
return 413 '{"error":"Payload too large (413). Please upload a smaller file."}';
|
|
}
|
|
|
|
# Ensure 429 (rate limited) returns JSON + CORS
|
|
error_page 429 = @rate_limited;
|
|
location @rate_limited {
|
|
default_type application/json;
|
|
add_header 'Access-Control-Allow-Origin' $cors_origin always;
|
|
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
|
return 429 '{"error":"Too many requests. Please slow down."}';
|
|
}
|
|
|
|
location / {
|
|
limit_req zone=spanglish_photo_limit burst=40 nodelay;
|
|
|
|
# Preflight
|
|
if ($request_method = 'OPTIONS') {
|
|
add_header 'Access-Control-Allow-Origin' $cors_origin always;
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, PATCH, OPTIONS' always;
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
|
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
|
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
|
|
add_header 'Access-Control-Max-Age' 86400 always;
|
|
add_header 'Content-Type' 'text/plain; charset=utf-8';
|
|
add_header 'Content-Length' 0;
|
|
return 204;
|
|
}
|
|
|
|
proxy_pass http://spanglish_photo_api;
|
|
proxy_http_version 1.1;
|
|
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
proxy_hide_header 'Access-Control-Allow-Origin';
|
|
proxy_hide_header 'Access-Control-Allow-Methods';
|
|
proxy_hide_header 'Access-Control-Allow-Headers';
|
|
proxy_hide_header 'Access-Control-Allow-Credentials';
|
|
proxy_hide_header 'Access-Control-Expose-Headers';
|
|
|
|
proxy_read_timeout 300s;
|
|
proxy_connect_timeout 300s;
|
|
|
|
# Buffer large image uploads to disk rather than memory
|
|
proxy_request_buffering on;
|
|
proxy_max_temp_file_size 1024m;
|
|
}
|
|
} |