Skip to content

Commit

Permalink
Increase CN nginx worker procs + Update caching rules (#3883)
Browse files Browse the repository at this point in the history
  • Loading branch information
SidSethi committed Sep 21, 2022
1 parent 1712c8c commit 8a4cb0c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions creator-node/nginx_conf/nginx.conf
Expand Up @@ -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=<value>`
# Nginx location regex examples: https://linuxhint.com/nginx-location-regex-examples/

worker_processes 1;
worker_processes 8;

events {
worker_connections 4096;
Expand Down Expand Up @@ -34,7 +35,7 @@ http {
# Match the paths /ipfs/<cid: string> and /content/<cid: string>.
# 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;

Expand All @@ -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
Expand All @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit 8a4cb0c

Please sign in to comment.