Files
romm/docker/nginx/default.conf
Sam Dornan b48f6003b5 fix(nginx): scope gzip_static to the build output
In the http block gzip_static was inherited by every location, including
the internal /library/ and /cache/ ones that serve downloads. RomM handles
.gz and .tar.gz ROMs, so a library holding both Game.nes and Game.nes.gz
answered a request for the first with the second's bytes under
Content-Encoding: gzip. Reproduced against nginx with a real upstream
issuing X-Accel-Redirect: the download returned 73 bytes of gzip instead
of the 3000-byte ROM. Clients that do not transparently decode, and Range
resumes over /cache/, would have written the wrong file to disk.

It now sits in the three locations that serve the frontend build, where a
.gz sibling can only be one the build wrote. Verified both directions: the
ROM download returns the plain 3000 bytes with no Content-Encoding, and a
fingerprinted asset is still served from its precompressed sibling.

The test now guards the invariant rather than the directive's presence:
gzip_static must be absent from the http block and from every location
serving files the build did not produce.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HDXxq3vAxJVGhm1pQuK8V7
2026-09-12 02:04:03 +00:00

87 lines
2.8 KiB
Plaintext

load_module modules/ngx_http_js_module.so;
load_module modules/ngx_http_zip_module.so;
worker_processes auto;
pid /tmp/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
}
http {
client_body_temp_path /tmp/client_body 1 2;
fastcgi_temp_path /tmp/fastcgi 1 2;
proxy_temp_path /tmp/proxy;
uwsgi_temp_path /tmp/uwsgi;
scgi_temp_path /tmp/scgi;
sendfile on;
client_body_buffer_size 128k;
client_max_body_size 0;
client_header_buffer_size 1k;
large_client_header_buffers 4 16k;
send_timeout 600s;
keepalive_timeout 600s;
client_body_timeout 600s;
tcp_nopush on;
tcp_nodelay on;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1.2 TLSv1.3; # Dropping SSLv3/TLSv1/TLSv1.1, ref: POODLE
ssl_prefer_server_ciphers on;
js_import /etc/nginx/js/decode.js;
map $time_iso8601 $date {
~([^+]+)T $1;
}
map $time_iso8601 $time {
~T([0-9:]+)\+ $1;
}
# Map to extract the browser name (e.g., Chrome, Firefox, etc.)
map $http_user_agent $browser {
default "Unknown";
"~Chrome/" "Chrome";
"~Firefox/" "Firefox";
"~Safari/" "Safari";
"~Edge/" "Edge";
"~Opera/" "Opera";
}
# Map to extract the OS (e.g., Windows, MacOS, Linux)
map $http_user_agent $os {
default "Unknown";
"~Windows NT" "Windows";
"~Macintosh" "macOS";
"~Linux" "Linux";
"~Android" "Android";
"~iPhone" "iOS";
}
#INFO: [nginx][2023-11-14 09:20:29] 127.0.0.1 - -"GET / HTTP/1.1" 500 177 "-" "Mozilla/5.0 (X11; Linux x86_64)"rt=0.000 uct="-" uht="-" urt="-"
log_format romm_logs 'INFO: [RomM][nginx][$date $time] '
'$remote_addr | $http_x_forwarded_for | '
'$request_method $request_uri $status | $body_bytes_sent | '
'$browser $os | $request_time';
access_log /dev/stdout romm_logs buffer=32k flush=5s;
error_log /dev/stderr;
gzip on;
gzip_proxied any;
gzip_vary on;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_min_length 1024;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/wasm image/svg+xml;
# The `wsgi_server` upstream is defined in a templated conf.d file so its
# port can track ${DEV_PORT} via envsubst (nginx.conf is not templated).
include /etc/nginx/conf.d/*.conf;
}