Skip to content

Instantly share code, notes, and snippets.

View johnhpatton's full-sized avatar

John H Patton johnhpatton

View GitHub Profile
@johnhpatton
johnhpatton / nginx.conf
Created February 4, 2021 02:28
Availability Location Block Snippet
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;
# http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_headers
@johnhpatton
johnhpatton / nginx-map-basics.conf
Created March 19, 2021 00:48
Basic Nginx Map Format
map $variable_to_check $variable_to_set {
"check_if_variable_matches_me" "variable_matches_checked_value";
default "no_match";
}
@johnhpatton
johnhpatton / nginx-map-as-if-statement.sh
Created March 19, 2021 00:55
Converted nginx map to bash if statement
if [ "$variable_to_check" == "check_if_variable_matches_me" ]; then
variable_to_set="variable_matches_checked_value"
else
variable_to_set="no_match"
fi
@johnhpatton
johnhpatton / nginx-map-as-case-statement.sh
Created March 19, 2021 00:59
Nginx map as bash case statement
case $variable_to_check in:
check_if_variable_matches_me)
variable_to_set="variable_matches_checked_value"
;;
*)
variable_to_set="no_match"
;;
esac
@johnhpatton
johnhpatton / nginx-map-multiple-comparisons.sh
Created March 19, 2021 01:03
Nginx Map with Multiple Comparisons
map $thing $useful_variable {
"thing_matches_me" "thing_matched_1";
"nope_thing_matches_me" "thing_matched_2";
default "no_match";
}
@johnhpatton
johnhpatton / nginx-compare-two-vars-not-possible.conf
Created March 19, 2021 01:06
Example of nginx comparison configuration that is not possible
if ($thing1 = $thing2) {
return 301 "{'Error': 'Things don't match!'}";
}
@johnhpatton
johnhpatton / nginx-compare-two-variables.conf
Created March 19, 2021 01:09
Nginx comparison of two variables
# if delimeter between two variables is ':'
map $thing1:$thing2 $do_things_match {
"~^([^:]+):\1$" 1;
default 0;
}
@johnhpatton
johnhpatton / nginx-maps-malformed-uri.conf
Created March 19, 2021 11:44
Nginx Maps Malformed URI
map $request_uri $uri_only {
"~^(?<u>[^\?]+)\?(?:.*)?" $u;
default $request_uri;
}
map $uri_only $shun_if_client_is_a_baddy {
"~\/\/" 1;
"~*%2f" 1;
default 0;
}
if ($shun_if_client_is_a_baddy = 1) {
return 403 'You shall not pass!!!';
}
@johnhpatton
johnhpatton / nginx-compare-two-request-variables.conf
Created March 19, 2021 12:24
Nginx comparison of two nginx request variables
map $arg_FOO:$http_x_bar $shun_mismatched_payload {
"~^([^:]+):\1$" 1;
default 0;
}