-
-
Save nginx-gists/37ce65292a06219ff8d35d293c05e0b5 to your computer and use it in GitHub Desktop.
Revisions
-
nginx-gists revised this gist
Dec 9, 2021 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,10 +20,10 @@ server { include api_conf.d/*.conf; # Error responses error_page 404 = @400; # Treat invalid paths as bad requests proxy_intercept_errors on; # Do not send backend errors to client include api_json_errors.conf; # API client-friendly JSON errors default_type application/json; # If no content-type, assume JSON } # vim: syntax=nginx -
nginx-gists revised this gist
Oct 12, 2021 . 6 changed files with 8 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,8 @@ include api_backends.conf; include api_keys.conf; server { access_log /var/log/nginx/api_access.log main; # Each API may also log to a # separate file listen 443 ssl; server_name api.example.com; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,8 @@ include api_backends.conf; include api_keys.conf; server { access_log /var/log/nginx/api_access.log main; # Each API may also log to a # separate file listen 443 ssl; server_name api.example.com; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # Warehouse API # location /api/warehouse/ { # Policy configuration here (authentication, rate limiting, logging...) # access_log /var/log/nginx/warehouse_api.log main; auth_request /_validate_apikey; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # Warehouse API (precise definition) # location /api/warehouse/ { # Policy configuration here (authentication, rate limiting, logging...) # access_log /var/log/nginx/warehouse_api.log main; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ rewrite ^/api/warehouse/inventory/item/price/(.*) /api/warehouse/pricing/$1; # Warehouse API # location /api/warehouse/ { # Policy configuration here (authentication, rate limiting, logging...) # access_log /var/log/nginx/warehouse_api.log main; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # Warehouse API # location /api/warehouse/ { # Policy configuration here (authentication, rate limiting, logging...) # access_log /var/log/nginx/warehouse_api.log main; -
nginx-gists revised this gist
Jan 20, 2021 . 5 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes. -
nginx-gists revised this gist
Jan 20, 2021 . 7 changed files with 114 additions and 250 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,33 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,114 @@ #!/usr/bin/env bash # # oas2nginx.sh (c) NGINX, Inc. [v0.5 13-Jan-2020] Liam Crilly <[email protected]> # # Converts OpenAPI/Swagger spec into nginx.conf snippet (server context) as per # https://www.nginx.com/blog/deploying-nginx-plus-as-an-api-gateway-part-1/ # Requires shyaml for YAML processing: https://github.com/0k/shyaml # Defaults # BASEPATH="" PREFIX_PATH="" UPSTREAM="my_backend" if [ $# -lt 1 ]; then echo "USAGE: ${0##*/} [options] oas_spec.yaml" echo " Converts OpenAPI/Swagger spec into nginx.conf snippet" echo " Options:" echo " -b | --basepath <basePath> # Override OAS basePath / servers path" echo " -p | --prefix <prefix path> # Apply further prefix to basePath" echo " -u | --upstream <upstream name> # Specify upstream group (default: $UPSTREAM)" exit 1 fi which shyaml > /dev/null if [ $? -ne 0 ]; then echo "${0##*/} ERROR: shyaml not found, see https://github.com/0k/shyaml" exit 1 fi while [ $# -gt 1 ]; do case "$1" in "-b" | "--basepath") BASEPATH=$2 shift; shift ;; "-p" | "--prefix") PREFIX_PATH=$2 shift; shift ;; "-u" | "--upstream") UPSTREAM=$2 shift; shift ;; *) echo "${0##*/} ERROR: Invalid command line option ($1)" exit 1 ;; esac done if [ ! -f $1 ]; then echo "${0##*/} ERROR: Cannot open $1" exit 1 fi if [ "$BASEPATH" == "" ]; then OAS_VERSION=`shyaml -q get-value openapi < $1` if [ $? -eq 0 ]; then echo "${0##*/} INFO: OpenAPI $OAS_VERSION" > /dev/stderr BASEPATH=`shyaml get-value servers < $1 2> /dev/null | grep url: | cut -f2- -d: | tail -1 | tr -d '[:blank:]'` else echo "${0##*/} INFO: OAS/Swagger v2" > /dev/stderr BASEPATH=`shyaml -q get-value basePath < $1` fi if [ "$BASEPATH" == "" ]; then echo "${0##*/}: WARNING: No basePath found in OAS" > /dev/stderr BASEPATH=/ fi fi if [ "`echo $BASEPATH | grep -c http`" == "1" ]; then echo "${0##*/}: INFO: Stripping scheme and hostname from basepath URL" > /dev/stderr BASEPATH=/`echo $BASEPATH | cut -f4- -d/` fi echo "${0##*/}: INFO: Using basePath $BASEPATH" if [ "$PREFIX_PATH" != "" ]; then echo "# Strip prefix" echo "rewrite ^$PREFIX_PATH/\(.*\)$ \1 last;" echo "" fi echo "location $BASEPATH/ {" | sed -e 's_//_/_g' echo " # Policy section here" echo " #" echo " error_page 403 = @405;" echo "" for SWAGGER_PATH in `shyaml keys paths < $1`; do # Convert path templates to regular expressions URI=`echo $SWAGGER_PATH | sed -e "s/\({.*}\)/\[\^\/\]\+/g"` if [ "$SWAGGER_PATH" == "$URI" ]; then # Exact match when no path templates echo " location = $BASEPATH$URI {" | sed -e 's_//_/_g' else # Regex match echo " location ~ ^$BASEPATH$URI\$ {" | sed -e 's_//_/_g' fi ESCAPED_PATH=`echo $SWAGGER_PATH | sed -e 's/\./\\\./g'` METHODS=`shyaml keys paths.$ESCAPED_PATH < $1 | grep -v parameters | tr '\n' ' '` if [ "$METHODS" != "" ]; then echo " limit_except $METHODS{ deny all; }" fi echo " proxy_pass http://$UPSTREAM;" echo " }" done echo "" echo " return 404;" echo "}" This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,113 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,34 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,29 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +0,0 @@ -
nginx-gists revised this gist
Jan 20, 2021 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,5 +39,4 @@ server { } } # vim: syntax=nginx -
nginx-gists revised this gist
Jan 20, 2021 . 6 changed files with 168 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ include api_backends.conf; include api_keys.conf; server { access_log /var/log/nginx/api_access.log main; # Each API may also log to a separate file listen 443 ssl; server_name api.example.com; # TLS config ssl_certificate /etc/ssl/certs/api.example.com.crt; ssl_certificate_key /etc/ssl/private/api.example.com.key; ssl_session_cache shared:SSL:10m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_protocols TLSv1.2 TLSv1.3; # API definitions, one per file include api_conf.d/*.conf; # Error responses error_page 404 = @400; # Invalid paths are treated as bad requests proxy_intercept_errors on; # Do not send backend errors to the client include api_json_errors.conf; # API client friendly JSON error responses default_type application/json; # If no content-type then assume JSON } # vim: syntax=nginx This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ # Warehouse API # location /api/warehouse/ { # Policy configuration here (authentication, rate limiting, logging, more...) # access_log /var/log/nginx/warehouse_api.log main; auth_request /_validate_apikey; # URI routing # location /api/warehouse/inventory { proxy_pass http://warehouse_inventory; } location /api/warehouse/pricing { proxy_pass http://warehouse_pricing; } return 404; # Catch-all } # vim: syntax=nginx This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ # Warehouse API (precise definition) # location /api/warehouse/ { # Policy configuration here (authentication, rate limiting, logging, more...) # access_log /var/log/nginx/warehouse_api.log main; # URI routing # location = /api/warehouse/inventory { # Complete inventory proxy_pass http://warehouse_inventory; } location ~ ^/api/warehouse/inventory/shelf/[^/]+$ { # Shelf inventory proxy_pass http://warehouse_inventory; } location ~ ^/api/warehouse/inventory/shelf/[^/]+/box/[^/]+$ { # Box on shelf proxy_pass http://warehouse_inventory; } location ~ ^/api/warehouse/pricing/[^/]+$ { # Price for specific item proxy_pass http://warehouse_pricing; } return 404; # Catch-all } # vim: syntax=nginx This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ # Rewrite rules # rewrite ^/api/warehouse/inventory/item/price/(.*) /api/warehouse/pricing/$1; # Warehouse API # location /api/warehouse/ { # Policy configuration here (authentication, rate limiting, logging, more...) # access_log /var/log/nginx/warehouse_api.log main; # URI routing # location /api/warehouse/inventory { proxy_pass http://warehouse_inventory; } location /api/warehouse/pricing { proxy_pass http://warehouse_pricing; } return 404; # Catch-all } # vim: syntax=nginx This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ # Warehouse API # location /api/warehouse/ { # Policy configuration here (authentication, rate limiting, logging, more...) # access_log /var/log/nginx/warehouse_api.log main; # URI routing # location /api/warehouse/inventory { proxy_pass http://warehouse_inventory; } location /api/warehouse/pricing { proxy_pass http://warehouse_pricing; } return 404; # Catch-all } # vim: syntax=nginx This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ include api_backends.conf; include api_keys.conf; server { access_log /var/log/nginx/api_access.log main; # Each API may also log to a separate file listen 443 ssl; server_name api.example.com; # TLS config ssl_certificate /etc/ssl/certs/api.example.com.crt; ssl_certificate_key /etc/ssl/private/api.example.com.key; ssl_session_cache shared:SSL:10m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_protocols TLSv1.2 TLSv1.3; # API definitions, one per file include api_conf.d/*.conf; # Error responses error_page 404 = @400; # Invalid paths are treated as bad requests proxy_intercept_errors on; # Do not send backend errors to the client include api_json_errors.conf; # API client friendly JSON error responses default_type application/json; # If no content-type then assume JSON # API key validation location = /_validate_apikey { internal; if ($http_apikey = "") { return 401; # Unauthorized } if ($api_client_name = "") { return 403; # Forbidden } return 204; # OK (no content) } } # vim: syntax=nginx oas2nginx.sh -
nginx-gists revised this gist
Jan 20, 2021 . 1 changed file with 0 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,9 +14,4 @@ location = /_warehouse { proxy_pass http://$upstream$request_uri; } # vim: syntax=nginx -
nginx-gists revised this gist
Jan 20, 2021 . 8 changed files with 193 additions and 219 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,13 @@ log_format api_main '$remote_addr - $remote_user [$time_local] "$request"' '$status $body_bytes_sent "$http_referer" "$http_user_agent"' '"$http_x_forwarded_for" "$api_name"'; include api_backends.conf; include api_keys.conf; server { set $api_name -; # Start with an undefined API name, each API will update this value access_log /var/log/nginx/api_access.log api_main; # Each API may also log to a separate file listen 443 ssl; server_name api.example.com; @@ -13,7 +18,7 @@ server { ssl_session_cache shared:SSL:10m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_protocols TLSv1.1 TLSv1.2; # API definitions, one per file include api_conf.d/*.conf; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,42 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,114 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,113 @@ #!/usr/bin/env bash # # swagger2nginx.sh (c) NGINX, Inc. [v0.2 03-May-2018] Liam Crilly <[email protected]> # # Requires shyaml for YAML processing: https://github.com/0k/shyaml if [ $# -lt 1 ]; then echo "### USAGE: `basename $0` [options] swagger_file.yaml" echo "### Options:" echo "### -b | --basepath <basePath> # Override Swagger basePath" echo "### -l | --location # Create policy location (requires -u)" echo "### -n | --api-name <API name> # Override Swagger title" echo "### -p | --prefix <prefix path> # Apply prefix to basePath" echo "### -u | --upstream <upstream name> # Specify upstream group" exit 1 fi which shyaml if [ $? -ne 0 ]; then echo "### `basename $0` ERROR: shyaml not found, see https://github.com/0k/shyaml" exit 1 fi API_NAME="" DO_LOCATION=0 BASEPATH="" PREFIX_PATH="" UPSTREAM="" while [ $# -gt 1 ]; do case "$1" in "-b" | "--basepath") BASEPATH=$2 shift; shift ;; "-l" | "--location") DO_LOCATION=1 shift ;; "-n" | "--api-name") API_NAME=$2 shift; shift ;; "-p" | "--prefix") PREFIX_PATH=$2 shift; shift ;; "-u" | "--upstream") UPSTREAM=$2 shift; shift ;; *) echo "### `basename $0` ERROR: Invalid command line option ($1)" exit 1 ;; esac done if [ $DO_LOCATION -eq 1 ] && [ "$UPSTREAM" == "" ]; then echo "### `basename $0` ERROR: Policy location requires upstream --upstream name" exit 1 fi if [ ! -f $1 ]; then echo "### `basename $0` ERROR: Cannot open $1" exit 1 fi if [ "$API_NAME" == "" ]; then # Convert title to NGINX-friendly API name API_NAME=`shyaml get-value info.title < $1 | tr '[:space:]' '_' | tr -cd '[:alnum:]_-' 2> /dev/null` if [ "$API_NAME" == "" ]; then echo "### `basename $0` ERROR: Swagger file has missing/invalid title for API name" exit 1 fi fi if [ "$BASEPATH" == "" ]; then BASEPATH=`shyaml get-value basePath < $1 2> /dev/null` if [ "$BASEPATH" == "" ]; then echo "### `basename $0` ERROR: No basePath found in Swagger" exit 1 fi fi BASEPATH=$PREFIX_PATH$BASEPATH for SWAGGER_PATH in `shyaml keys paths < $1`; do # Convert path templates to regular expressions URI=`echo $SWAGGER_PATH | sed -e "s/\({.*}\)/\[\^\/\]\*/g"` if [ "$SWAGGER_PATH" == "$URI" ]; then echo "location = $BASEPATH$URI {" # Exact match when no path templates else echo "location ~ ^$BASEPATH$URI\$ {" # Regex match fi METHODS=`shyaml keys paths.$SWAGGER_PATH < $1 | grep -v parameters | tr '\n' ' '` if [ "$METHODS" != "" ]; then echo " limit_except $METHODS{}" fi if [ "$UPSTREAM" != "" ]; then echo " set \$upstream $UPSTREAM;" fi echo " rewrite ^ /_$API_NAME last;" echo "}" done if [ $DO_LOCATION -eq 1 ]; then echo "" echo "location = /_$API_NAME {" echo " proxy_pass http://\$upstream\$request_uri;" echo "}" This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,21 @@ # Policy section # location = /_warehouse { internal; set $api_name "Warehouse"; if ($http_apikey = "") { return 401; # Unauthorized (please authenticate) } if ($api_client_name = "") { return 403; # Forbidden (invalid API key) } proxy_pass http://$upstream$request_uri; } # vim: syntax=nginx return 404; # Catch-all } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,29 +1,34 @@ # API definition (precise) # location = /api/warehouse/inventory { # Complete inventory set $upstream inventory_service; rewrite ^ /_warehouse last; } location ~ ^/api/warehouse/inventory/shelf/[^/]*$ { # Shelf inventory set $upstream inventory_service; rewrite ^ /_warehouse last; } location ~ ^/api/warehouse/inventory/shelf/[^/]*/box/[^/]*$ { # Box on shelf set $upstream inventory_service; rewrite ^ /_warehouse last; } location ~ ^/api/warehouse/pricing/[^/]*$ { # Price for specific item set $upstream pricing_service; rewrite ^ /_warehouse last; } # Policy section # location = /_warehouse { internal; set $api_name warehouse_api; # Policy configuration here (authentication, rate limiting, logging, more...) proxy_pass http://$upstream$request_uri; } # vim: syntax=nginx This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,24 +2,28 @@ # rewrite ^/api/warehouse/inventory/item/price/(.*) /api/warehouse/pricing/$1; # API definition # location /api/warehouse/inventory { set $upstream inventory_service; rewrite ^(.*)$ /_warehouse$1 last; } location /api/warehouse/pricing { set $upstream pricing_service; rewrite ^(.*)$ /_warehouse$1 last; } # Policy section # location /_warehouse { internal; set $api_name "Warehouse"; # Policy configuration here (authentication, rate limiting, logging, more...) rewrite ^/_warehouse/(.*)$ /$1 break; # Remove /_warehouse prefix proxy_pass http://$upstream; # Proxy the rewritten URI } # vim: syntax=nginx This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,24 @@ # API definition # location /api/warehouse/inventory { set $upstream warehouse_inventory; rewrite ^ /_warehouse last; } location /api/warehouse/pricing { set $upstream warehouse_pricing; rewrite ^ /_warehouse last; } # Policy section # location = /_warehouse { internal; set $api_name "Warehouse"; # Policy configuration here (authentication, rate limiting, logging, more...) proxy_pass http://$upstream$request_uri; } # vim: syntax=nginx -
nginx-gists revised this gist
Jan 19, 2021 . 8 changed files with 220 additions and 203 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,8 @@ include api_backends.conf; include api_keys.conf; server { access_log /var/log/nginx/api_access.log main; # Each API may also log to a separate file listen 443 ssl; server_name api.example.com; @@ -18,7 +13,7 @@ server { ssl_session_cache shared:SSL:10m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_protocols TLSv1.2 TLSv1.3; # API definitions, one per file include api_conf.d/*.conf; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ include api_backends.conf; include api_keys.conf; server { access_log /var/log/nginx/api_access.log main; # Each API may also log to a separate file listen 443 ssl; server_name api.example.com; # TLS config ssl_certificate /etc/ssl/certs/api.example.com.crt; ssl_certificate_key /etc/ssl/private/api.example.com.key; ssl_session_cache shared:SSL:10m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_protocols TLSv1.2 TLSv1.3; # API definitions, one per file include api_conf.d/*.conf; # Error responses error_page 404 = @400; # Invalid paths are treated as bad requests proxy_intercept_errors on; # Do not send backend errors to the client include api_json_errors.conf; # API client friendly JSON error responses default_type application/json; # If no content-type then assume JSON # API key validation location = /_validate_apikey { internal; if ($http_apikey = "") { return 401; # Unauthorized } if ($api_client_name = "") { return 403; # Forbidden } return 204; # OK (no content) } } # vim: syntax=nginx This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,114 @@ #!/usr/bin/env bash # # oas2nginx.sh (c) NGINX, Inc. [v0.5 13-Jan-2020] Liam Crilly <[email protected]> # # Converts OpenAPI/Swagger spec into nginx.conf snippet (server context) as per # https://www.nginx.com/blog/deploying-nginx-plus-as-an-api-gateway-part-1/ # Requires shyaml for YAML processing: https://github.com/0k/shyaml # Defaults # BASEPATH="" PREFIX_PATH="" UPSTREAM="my_backend" if [ $# -lt 1 ]; then echo "USAGE: ${0##*/} [options] oas_spec.yaml" echo " Converts OpenAPI/Swagger spec into nginx.conf snippet" echo " Options:" echo " -b | --basepath <basePath> # Override OAS basePath / servers path" echo " -p | --prefix <prefix path> # Apply further prefix to basePath" echo " -u | --upstream <upstream name> # Specify upstream group (default: $UPSTREAM)" exit 1 fi which shyaml > /dev/null if [ $? -ne 0 ]; then echo "${0##*/} ERROR: shyaml not found, see https://github.com/0k/shyaml" exit 1 fi while [ $# -gt 1 ]; do case "$1" in "-b" | "--basepath") BASEPATH=$2 shift; shift ;; "-p" | "--prefix") PREFIX_PATH=$2 shift; shift ;; "-u" | "--upstream") UPSTREAM=$2 shift; shift ;; *) echo "${0##*/} ERROR: Invalid command line option ($1)" exit 1 ;; esac done if [ ! -f $1 ]; then echo "${0##*/} ERROR: Cannot open $1" exit 1 fi if [ "$BASEPATH" == "" ]; then OAS_VERSION=`shyaml -q get-value openapi < $1` if [ $? -eq 0 ]; then echo "${0##*/} INFO: OpenAPI $OAS_VERSION" > /dev/stderr BASEPATH=`shyaml get-value servers < $1 2> /dev/null | grep url: | cut -f2- -d: | tail -1 | tr -d '[:blank:]'` else echo "${0##*/} INFO: OAS/Swagger v2" > /dev/stderr BASEPATH=`shyaml -q get-value basePath < $1` fi if [ "$BASEPATH" == "" ]; then echo "${0##*/}: WARNING: No basePath found in OAS" > /dev/stderr BASEPATH=/ fi fi if [ "`echo $BASEPATH | grep -c http`" == "1" ]; then echo "${0##*/}: INFO: Stripping scheme and hostname from basepath URL" > /dev/stderr BASEPATH=/`echo $BASEPATH | cut -f4- -d/` fi echo "${0##*/}: INFO: Using basePath $BASEPATH" if [ "$PREFIX_PATH" != "" ]; then echo "# Strip prefix" echo "rewrite ^$PREFIX_PATH/\(.*\)$ \1 last;" echo "" fi echo "location $BASEPATH/ {" | sed -e 's_//_/_g' echo " # Policy section here" echo " #" echo " error_page 403 = @405;" echo "" for SWAGGER_PATH in `shyaml keys paths < $1`; do # Convert path templates to regular expressions URI=`echo $SWAGGER_PATH | sed -e "s/\({.*}\)/\[\^\/\]\+/g"` if [ "$SWAGGER_PATH" == "$URI" ]; then # Exact match when no path templates echo " location = $BASEPATH$URI {" | sed -e 's_//_/_g' else # Regex match echo " location ~ ^$BASEPATH$URI\$ {" | sed -e 's_//_/_g' fi ESCAPED_PATH=`echo $SWAGGER_PATH | sed -e 's/\./\\\./g'` METHODS=`shyaml keys paths.$ESCAPED_PATH < $1 | grep -v parameters | tr '\n' ' '` if [ "$METHODS" != "" ]; then echo " limit_except $METHODS{ deny all; }" fi echo " proxy_pass http://$UPSTREAM;" echo " }" done echo "" echo " return 404;" echo "}" This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,114 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,30 +1,22 @@ # Warehouse API # location /api/warehouse/ { # Policy configuration here (authentication, rate limiting, logging, more...) # access_log /var/log/nginx/warehouse_api.log main; auth_request /_validate_apikey; # URI routing # location /api/warehouse/inventory { proxy_pass http://warehouse_inventory; } location /api/warehouse/pricing { proxy_pass http://warehouse_pricing; } return 404; # Catch-all } # vim: syntax=nginx This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,34 +1,29 @@ # Warehouse API (precise definition) # location /api/warehouse/ { # Policy configuration here (authentication, rate limiting, logging, more...) # access_log /var/log/nginx/warehouse_api.log main; # URI routing # location = /api/warehouse/inventory { # Complete inventory proxy_pass http://warehouse_inventory; } location ~ ^/api/warehouse/inventory/shelf/[^/]+$ { # Shelf inventory proxy_pass http://warehouse_inventory; } location ~ ^/api/warehouse/inventory/shelf/[^/]+/box/[^/]+$ { # Box on shelf proxy_pass http://warehouse_inventory; } location ~ ^/api/warehouse/pricing/[^/]+$ { # Price for specific item proxy_pass http://warehouse_pricing; } return 404; # Catch-all } # vim: syntax=nginx This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,28 +2,24 @@ # rewrite ^/api/warehouse/inventory/item/price/(.*) /api/warehouse/pricing/$1; # Warehouse API # location /api/warehouse/ { # Policy configuration here (authentication, rate limiting, logging, more...) # access_log /var/log/nginx/warehouse_api.log main; # URI routing # location /api/warehouse/inventory { proxy_pass http://warehouse_inventory; } location /api/warehouse/pricing { proxy_pass http://warehouse_pricing; } return 404; # Catch-all } # vim: syntax=nginx This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,21 @@ # Warehouse API # location /api/warehouse/ { # Policy configuration here (authentication, rate limiting, logging, more...) # access_log /var/log/nginx/warehouse_api.log main; # URI routing # location /api/warehouse/inventory { proxy_pass http://warehouse_inventory; } location /api/warehouse/pricing { proxy_pass http://warehouse_pricing; } return 404; # Catch-all } # vim: syntax=nginx -
nginx-gists revised this gist
Jun 21, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ location /api/warehouse/inventory { location /api/warehouse/pricing { set $upstream pricing_service; rewrite ^(.*)$ /_warehouse$1 last; } # Policy section -
nginx-gists revised this gist
May 25, 2018 . No changes.There are no files selected for viewing
-
nginx-gists revised this gist
May 16, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ log_format api_main '$remote_addr - $remote_user [$time_local] "$request"' '$status $body_bytes_sent "$http_referer" "$http_user_agent"' '"$http_x_forwarded_for" "$api_name"'; include api_backends.conf; include api_keys.conf; server { @@ -25,7 +25,7 @@ server { # Error responses error_page 404 = @400; # Invalid paths are treated as bad requests proxy_intercept_errors on; # Do not send backend errors to the client include api_json_errors.conf; # API client friendly JSON error responses default_type application/json; # If no content-type then assume JSON } -
nginx-gists renamed this gist
May 16, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
nginx-gists revised this gist
May 15, 2018 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ log_format api_main '$remote_addr - $remote_user [$time_local] "$request"' '$status $body_bytes_sent "$http_referer" "$http_user_agent"' '"$http_x_forwarded_for" "$api_name"'; include api_endpoints.conf; include api_keys.conf; -
nginx-gists revised this gist
May 14, 2018 . 3 changed files with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,14 +4,17 @@ location = /api/warehouse/inventory { # Complete inventory set $upstream inventory_service; rewrite ^ /_warehouse last; } location ~ ^/api/warehouse/inventory/shelf/[^/]*$ { # Shelf inventory set $upstream inventory_service; rewrite ^ /_warehouse last; } location ~ ^/api/warehouse/inventory/shelf/[^/]*/box/[^/]*$ { # Box on shelf set $upstream inventory_service; rewrite ^ /_warehouse last; } location ~ ^/api/warehouse/pricing/[^/]*$ { # Price for specific item set $upstream pricing_service; rewrite ^ /_warehouse last; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,7 @@ location /api/warehouse/inventory { set $upstream inventory_service; rewrite ^(.*)$ /_warehouse$1 last; } location /api/warehouse/pricing { set $upstream pricing_service; rewrite ^(.*) /_warehouse$1 last; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ location /api/warehouse/inventory { set $upstream warehouse_inventory; rewrite ^ /_warehouse last; } location /api/warehouse/pricing { set $upstream warehouse_pricing; rewrite ^ /_warehouse last; -
lcrilly revised this gist
May 11, 2018 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,6 +31,15 @@ location @426 { return 426 '{"status":426,"message":"HTTP request was sent to HT error_page 429 = @429; location @429 { return 429 '{"status":429,"message":"API rate limit exceeded"}\n'; } error_page 495 = @495; location @495 { return 495 '{"status":495,"message":"Client certificate authentication error"}\n'; } error_page 496 = @496; location @496 { return 496 '{"status":496,"message":"Client certificate not presented"}\n'; } error_page 497 = @497; location @497 { return 497 '{"status":497,"message":"HTTP request was sent to mutual TLS port"}\n'; } error_page 500 = @500; location @500 { return 500 '{"status":500,"message":"Server error"}\n'; } -
lcrilly revised this gist
May 3, 2018 . 1 changed file with 30 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ # API definition # location /api/warehouse/pricing { limit_except GET POST {} set $upstream pricing_service; rewrite ^ /_warehouse last; } location /api/warehouse/inventory { limit_except GET {} set $upstream inventory_service; rewrite ^(.*)$ /_warehouse$1 last; } # Policy section # location = /_warehouse { internal; set $api_name "Warehouse"; if ($http_apikey = "") { return 401; # Unauthorized (please authenticate) } if ($api_client_name = "") { return 403; # Forbidden (invalid API key) } proxy_pass http://$upstream$request_uri; } # vim: syntax=nginx -
lcrilly revised this gist
May 3, 2018 . 1 changed file with 18 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,26 @@ #!/usr/bin/env bash # # swagger2nginx.sh (c) NGINX, Inc. [v0.2 03-May-2018] Liam Crilly <[email protected]> # # Requires shyaml for YAML processing: https://github.com/0k/shyaml if [ $# -lt 1 ]; then echo "### USAGE: `basename $0` [options] swagger_file.yaml" echo "### Options:" echo "### -b | --basepath <basePath> # Override Swagger basePath" echo "### -l | --location # Create policy location (requires -u)" echo "### -n | --api-name <API name> # Override Swagger title" echo "### -p | --prefix <prefix path> # Apply prefix to basePath" echo "### -u | --upstream <upstream name> # Specify upstream group" exit 1 fi which shyaml if [ $? -ne 0 ]; then echo "### `basename $0` ERROR: shyaml not found, see https://github.com/0k/shyaml" exit 1 fi API_NAME="" DO_LOCATION=0 BASEPATH="" @@ -47,6 +55,11 @@ while [ $# -gt 1 ]; do esac done if [ $DO_LOCATION -eq 1 ] && [ "$UPSTREAM" == "" ]; then echo "### `basename $0` ERROR: Policy location requires upstream --upstream name" exit 1 fi if [ ! -f $1 ]; then echo "### `basename $0` ERROR: Cannot open $1" exit 1 @@ -93,9 +106,9 @@ for SWAGGER_PATH in `shyaml keys paths < $1`; do echo "}" done if [ $DO_LOCATION -eq 1 ]; then echo "" echo "location = /_$API_NAME {" echo " proxy_pass http://\$upstream\$request_uri;" echo "}" fi -
lcrilly revised this gist
May 2, 2018 . 1 changed file with 101 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,101 @@ #!/usr/bin/env bash # # swagger2nginx.sh (c) NGINX, Inc. [v0.1 02-May-2018] Liam Crilly <[email protected]> if [ $# -lt 1 ]; then echo "### USAGE: `basename $0` [options] <swagger_file.yaml>" echo "### Options:" echo "### -b | --basepath <basePath> # Override Swagger basePath" echo "### -l | --location # Create policy location" echo "### -n | --api-name <API name> # Override Swagger title" echo "### -p | --prefix <prefix path> # Apply prefix to basePath" echo "### -u | --upstream <upstream name> # Specify upstream group" exit 1 fi API_NAME="" DO_LOCATION=0 BASEPATH="" PREFIX_PATH="" UPSTREAM="" while [ $# -gt 1 ]; do case "$1" in "-b" | "--basepath") BASEPATH=$2 shift; shift ;; "-l" | "--location") DO_LOCATION=1 shift ;; "-n" | "--api-name") API_NAME=$2 shift; shift ;; "-p" | "--prefix") PREFIX_PATH=$2 shift; shift ;; "-u" | "--upstream") UPSTREAM=$2 shift; shift ;; *) echo "### `basename $0` ERROR: Invalid command line option ($1)" exit 1 ;; esac done if [ ! -f $1 ]; then echo "### `basename $0` ERROR: Cannot open $1" exit 1 fi if [ "$API_NAME" == "" ]; then # Convert title to NGINX-friendly API name API_NAME=`shyaml get-value info.title < $1 | tr '[:space:]' '_' | tr -cd '[:alnum:]_-' 2> /dev/null` if [ "$API_NAME" == "" ]; then echo "### `basename $0` ERROR: Swagger file has missing/invalid title for API name" exit 1 fi fi if [ "$BASEPATH" == "" ]; then BASEPATH=`shyaml get-value basePath < $1 2> /dev/null` if [ "$BASEPATH" == "" ]; then echo "### `basename $0` ERROR: No basePath found in Swagger" exit 1 fi fi BASEPATH=$PREFIX_PATH$BASEPATH for SWAGGER_PATH in `shyaml keys paths < $1`; do # Convert path templates to regular expressions URI=`echo $SWAGGER_PATH | sed -e "s/\({.*}\)/\[\^\/\]\*/g"` if [ "$SWAGGER_PATH" == "$URI" ]; then echo "location = $BASEPATH$URI {" # Exact match when no path templates else echo "location ~ ^$BASEPATH$URI\$ {" # Regex match fi METHODS=`shyaml keys paths.$SWAGGER_PATH < $1 | grep -v parameters | tr '\n' ' '` if [ "$METHODS" != "" ]; then echo " limit_except $METHODS{}" fi if [ "$UPSTREAM" != "" ]; then echo " set \$upstream $UPSTREAM;" fi echo " rewrite ^ /_$API_NAME last;" echo "}" done if [ $DO_LOCATION ]; then echo "" echo "location = /_$API_NAME {" echo " proxy_pass http://\$upstream\$request_uri;" echo "}" fi -
lcrilly revised this gist
May 1, 2018 . No changes.There are no files selected for viewing
-
lcrilly revised this gist
May 1, 2018 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,4 @@ log_format api_main '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for" "$api_name"'; include api_endpoints.conf; include api_keys.conf; -
lcrilly revised this gist
May 1, 2018 . 1 changed file with 28 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ # Rewrite rules # rewrite ^/api/warehouse/inventory/item/price/(.*) /api/warehouse/pricing/$1; # API definition # location /api/warehouse/inventory { set $upstream inventory_service; rewrite ^(.*)$ /_warehouse$1 last; } location /api/warehouse/pricing { set $upstream pricing_service; rewrite ^(.*) /_warehouse$1 last; } # Policy section # location /_warehouse { internal; set $api_name "Warehouse"; # Policy configuration here (authentication, rate limiting, logging, more...) rewrite ^/_warehouse/(.*)$ /$1 break; # Remove /_warehouse prefix proxy_pass http://$upstream; # Proxy the rewritten URI } # vim: syntax=nginx -
lcrilly revised this gist
May 1, 2018 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,18 @@ # API definition (precise) # location = /api/warehouse/inventory { # Complete inventory set $upstream inventory_service; rewrite ^ /_warehouse last; } location ~ ^/api/warehouse/inventory/shelf/[^/]*$ { # Shelf inventory set $upstream inventory_service; rewrite ^ /_warehouse last; } location ~ ^/api/warehouse/inventory/shelf/[^/]*/box/[^/]*$ { # Box on shelf set $upstream inventory_service; rewrite ^ /_warehouse last; } location ~ ^/api/warehouse/pricing/[^/]*$ { # Price for specific item set $upstream pricing_service; rewrite ^ /_warehouse last; } -
lcrilly revised this gist
May 1, 2018 . 1 changed file with 31 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ # API definition (precise) # location ~ ^/api/warehouse/inventory { # Complete inventory set $upstream inventory_service; rewrite ^ /_warehouse last; } location ~ ^/api/warehouse/inventory/shelf/[^/].* { # Shelf inventory set $upstream inventory_service; rewrite ^ /_warehouse last; } location ~ ^/api/warehouse/inventory/shelf/[^/].*/box/[^/].* { # Box on shelf set $upstream inventory_service; rewrite ^ /_warehouse last; } location ~ ^/api/warehouse/pricing/[^/].*$ { # Price for specific item set $upstream pricing_service; rewrite ^ /_warehouse last; } # Policy section # location = /_warehouse { internal; set $api_name warehouse_api; # Policy configuration here (authentication, rate limiting, logging, more...) proxy_pass http://$upstream$request_uri; } # vim: syntax=nginx -
lcrilly revised this gist
May 1, 2018 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,18 +2,18 @@ # location /api/warehouse/inventory { set $upstream warehouse_inventory; rewrite ^ /_warehouse last; } location /api/warehouse/pricing { set $upstream warehouse_pricing; rewrite ^ /_warehouse last; } # Policy section # location = /_warehouse { internal; set $api_name "Warehouse"; # Policy configuration here (authentication, rate limiting, logging, more...) -
lcrilly revised this gist
May 1, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ location /api/warehouse/pricing { rewrite ^(.*)$ /_warehouse$1 last; } # Policy section # location /_warehouse { internal; -
lcrilly revised this gist
May 1, 2018 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,13 @@ # API definition # location /api/warehouse/inventory { set $upstream warehouse_inventory; rewrite ^(.*)$ /_warehouse$1 last; } location /api/warehouse/pricing { set $upstream warehouse_pricing; rewrite ^(.*)$ /_warehouse$1 last; } # Policy block # -
lcrilly revised this gist
May 1, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ location /_warehouse { internal; set $api_name Warehouse; # Policy configuration here (authentication, rate limiting, logging, more...) proxy_pass http://$upstream$request_uri; } -
lcrilly revised this gist
May 1, 2018 . 1 changed file with 2 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,14 +13,9 @@ location /api/warehouse/inventory { # location /_warehouse { internal; set $api_name Warehouse; # Policy configuration here (authentication, rate limiting, logging, more... proxy_pass http://$upstream$request_uri; } -
lcrilly revised this gist
May 1, 2018 . 2 changed files with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,11 @@ upstream warehouse_inventory { zone inventory_service 64k; server 10.0.0.1:80; server 10.0.0.2:80; server 10.0.0.3:80; } upstream warehouse_pricing { zone pricing_service 64k; server 10.0.0.7:80; server 10.0.0.8:80; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,11 @@ # API definition # location /api/warehouse/pricing { set $upstream warehouse_pricing; rewrite ^(.*)$ /_warehouse$1 last; } location /api/warehouse/inventory { set $upstream warehouse_inventory; rewrite ^(.*)$ /_warehouse$1 last; }
NewerOlder