From c42b53a536481b9ec264d7866679030267103cc2 Mon Sep 17 00:00:00 2001 From: Evan Date: Thu, 6 Mar 2025 10:21:04 -0800 Subject: [PATCH] update nginx to cache public_lobbies and /api/env --- nginx.conf | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/nginx.conf b/nginx.conf index 953d552d3..04d7651a4 100644 --- a/nginx.conf +++ b/nginx.conf @@ -32,6 +32,8 @@ map $uri $uri_path { # Cache configuration proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g; +# API cache for frequently requested endpoints +proxy_cache_path /var/cache/nginx/api levels=1:2 keys_zone=API_CACHE:10m inactive=60m max_size=100m; server { listen 80 default_server; @@ -66,6 +68,44 @@ server { add_header Cache-Control "public, max-age=86400"; # 24 hours } + # /public_lobbies endpoint - Cache for 1 second to handle high request volume + location = /public_lobbies { + proxy_pass http://127.0.0.1:3000; + proxy_http_version 1.1; + + # Cache configuration + proxy_cache API_CACHE; + proxy_cache_valid 200 1s; # Cache successful responses for 1 second + proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504; + proxy_cache_lock on; + add_header X-Cache-Status $upstream_cache_status; + + # Standard proxy headers + 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; + } + + # /api/env endpoint - Cache for 1 hour + location = /api/env { + proxy_pass http://127.0.0.1:3000; + proxy_http_version 1.1; + + # Cache configuration + proxy_cache API_CACHE; + proxy_cache_valid 200 1h; # Cache successful responses for 1 hour + proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504; + proxy_cache_lock on; + add_header X-Cache-Status $upstream_cache_status; + + # Standard proxy headers + 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; + } + # Binary files caching location ~* \.(bin|dat|exe|dll|so|dylib)$ { proxy_pass http://127.0.0.1:3000;