Nginx

Last updated


This page covers the routing blocks, image cache settings, and security headers in config/nginx/nodes.conf.

Routing Blocks


locationUpstreamCacheNotes
~ /\.——deny all; blocks any path containing /. (including the trash)
~* ^/c/img/http://golang:8080images_cache120-second read / send timeouts
~* ^/upload/http://golang:8080NoneCommented-out allow / deny
~* ^/del/http://golang:8080NoneCommented-out allow / deny
/http://golang:8080NoneEverything else (including /check/state)

Regex locations match in order of appearance, and ~ /\. comes first, so it wins over /c/img/.

Image Cache


DirectiveValueEffect
proxy_cache_path/var/cache/nginx/images, keys_zone=images_cache:10m, max_size=2g, inactive=30dEvicted after 30 days without access
proxy_cache_valid200 302 301 304 7d; any 1m7 days for success, 1 minute otherwise
proxy_cache_use_staleerror timeout updating http_500 http_502 http_503 http_504Serve stale entries when the upstream fails
proxy_cache_lockonOnly one request per key goes upstream
proxy_cache_background_updateonRefresh stale entries in the background
add_header X-Cache-Status$upstream_cache_statusShows HIT / MISS

/c/img/ also adds add_header Cache-Control "public, max-age=604800" and expires 7d, which coexist with the headers the Go service sends. gzip is enabled for image types (gzip_comp_level 6, gzip_min_length 1000).

Security Settings


ItemSetting
Upload sizeclient_max_body_size 100M
HTTP methodsAnything other than GET / HEAD / POST / DELETE / PUT / OPTIONS returns 444 (connection closed)
Hidden headersserver_tokens off, plus upstream headers such as X-Powered-By
Security headersX-Content-Type-Options, X-Frame-Options, X-XSS-Protection, Referrer-Policy, Permissions-Policy, Content-Security-Policy

Enabling the Upload and Delete Allowlist


The Go service has no authentication; before exposing it, uncomment the rules in the /upload/ and /del/ blocks and list the allowed sources:
  1. location ~* ^/upload/ {
  2. allow 203.0.113.10;
  3. deny all;
  4. proxy_pass http://golang:8080;
  5. }
中文