Skip to content

Instantly share code, notes, and snippets.

@johnhpatton
Created September 27, 2020 21:02
Show Gist options
  • Save johnhpatton/3d9daaa99b49ebd15101552099ddeb17 to your computer and use it in GitHub Desktop.
Save johnhpatton/3d9daaa99b49ebd15101552099ddeb17 to your computer and use it in GitHub Desktop.
Availability Location Block
server {
...
location ~* ^/api/product/check_availability/.+ {
# The key zone to use for cache lookups.
# http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache
proxy_cache availability;
# Ignore Cache Control headers to allow proxy cache to work
# http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_headers
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
# Only one request at a time will be allowed to populate a new cache element identified.
# http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_lock
proxy_cache_lock on;
# Allow background updates, serve stale during update.
# NOTE: requires enabling serve stale on update.
# http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_background_update
proxy_cache_background_update on;
# Conditions allowing stale responses.
# http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_use_stale
proxy_cache_use_stale updating;
# http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_headers
# By default, proxy_cache lookups only occur on GET or HEAD methods. Uncomment
# if this is a POST request.
# http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_methods
#proxy_cache_methods POST;
# http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_key
proxy_cache_key $product_number;
# http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_valid
proxy_cache_valid 200 500 5s; # normal inventory or an error
proxy_cache_valid 201 1s; # low inventory
proxy_cache_valid 400 1m; # out of stock
proxy_pass http://availability_service$request_uri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment