From 8a4cb0c4aa09f3d3be1ae1c61cd64efbf5894e80 Mon Sep 17 00:00:00 2001 From: Sid Sethi <3323835+SidSethi@users.noreply.github.com> Date: Wed, 21 Sep 2022 09:36:33 -0400 Subject: [PATCH] Increase CN nginx worker procs + Update caching rules (#3883) --- creator-node/nginx_conf/nginx.conf | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/creator-node/nginx_conf/nginx.conf b/creator-node/nginx_conf/nginx.conf index 2eaf85a0391..9790febf894 100644 --- a/creator-node/nginx_conf/nginx.conf +++ b/creator-node/nginx_conf/nginx.conf @@ -2,8 +2,9 @@ # # Notes: # - any value below prefixed with $arg indicates a request query param, e.g. $arg_bypasscache will match query param `bypasscache=` +# Nginx location regex examples: https://linuxhint.com/nginx-location-regex-examples/ -worker_processes 1; +worker_processes 8; events { worker_connections 4096; @@ -34,7 +35,7 @@ http { # Match the paths /ipfs/ and /content/. # If present in cache, serve. Else, hit upstream server + update cache + serve. # http://nginx.org/en/docs/http/ngx_http_core_module.html#location - location ~ (/ipfs/|/content/) { + location ~ (/ipfs/|/content/|/file_lookup/) { proxy_cache cache; proxy_pass http://127.0.0.1:3000; @@ -46,10 +47,12 @@ http { proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; proxy_cache_background_update on; - # Cache only responses with status code = 200 for some duration before considered stale. + # Cache responses with certain status codes for some duration before considered stale. # Stale implies content will be fetched from the upstream server. Stale content WILL NOT # BE REMOVED from the cache. proxy_cache_valid 200 12h; + proxy_cache_valid 401 403 0s; + proxy_cache_valid any 1s; # When enabled, only one request at a time will be allowed to populate a new cache element # Other requests of the same cache element will either wait for a response to appear in the cache @@ -68,6 +71,8 @@ http { add_header X-Cache-Status $upstream_cache_status always; } + # Regex matches any path that begins with /health_check (case-sensitive) + # Note this will also include other health check routes /health_check/verbose, /health_check/sync, /health_check/duration, /health_check/duration/heartbeat, /health_check/fileupload location ~ (/health_check) { proxy_cache cache; @@ -76,10 +81,13 @@ http { # Set client IP as `X-Forwarded-For` response header proxy_set_header X-Forwarded-For $remote_addr; - # Never serve a stale response + # proxy_cache_use_stale + proxy_cache_background_update -> deliver stale content when client requests + # an item that is expired or in the process of being updated from origin server + proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; + proxy_cache_background_update on; - # Cache responses with 200 status, for 1 second - proxy_cache_valid 200 1s; + # Cache all responses for 1s + proxy_cache_valid any 1s; # Bypass cache with bypasscache=true query string and save new response to proxy cache proxy_cache_bypass $arg_bypasscache;