| #/* |
| # * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved. |
| # * |
| # * Permission is hereby granted, free of charge, to any person obtaining a |
| # * copy of this software and associated documentation files (the "Software"), |
| # * to deal in the Software without restriction, including without limitation |
| # * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| # * and/or sell copies of the Software, and to permit persons to whom the |
| # * Software is furnished to do so, subject to the following conditions: |
| # * |
| # * The above copyright notice and this permission notice shall be included in |
| # * all copies or substantial portions of the Software. |
| # * |
| # * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| # * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| # * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| # * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| # * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| # * DEALINGS IN THE SOFTWARE. |
| # * |
| # */ |
| |
| # |
| # NOTE: THIS CONFIG FILE ASSUMES ALL HOST NAMES ARE IN FORMAT <app_name>.api.any.domain |
| # |
| |
| #import the list of upstreams |
| include /etc/api-gateway/environment.conf.d/api-gateway-upstreams.http.conf; |
| |
| server { |
| server_name ~hello-world.api.(?<domain>.+); |
| } |
| |
| server { |
| listen 80; |
| # listen 8080; |
| |
| # listenes on <app_name>.api.any.domain with the assumption that the app_name has been defined in marathon. TBD what to do when the app is not found |
| server_name ~^(?<app_name>.[^\.]+)\.api\.(?<domain>.+); |
| |
| server_tokens off; |
| |
| #turn off the uninitialized_variable_warn ,as it writes to error_log , hence io |
| uninitialized_variable_warn off; |
| |
| # block ips of embargoed countries |
| if ( $blacklist ) { |
| return 403; |
| } |
| |
| include /etc/api-gateway/conf.d/commons/common-headers.conf; |
| include /etc/api-gateway/conf.d/includes/resolvers.conf; |
| |
| # Log locations with service name |
| access_log /var/log/api-gateway/access.log platform; |
| error_log /var/log/api-gateway/marathon_error.log debug; |
| |
| # include environment variables |
| include /etc/api-gateway/environment.conf.d/api-gateway-env-vars.server.conf; |
| |
| error_page 500 501 502 503 504 /50x.html; |
| |
| location /50x.html { |
| more_set_headers 'Content-Type: application/json'; |
| more_set_headers 'X-Request-Id: $requestId'; |
| return 500 '{"code":$status, "message":"Oops. Something went wrong. Check your URI and try again."}\n'; |
| } |
| |
| location / { |
| # ---------------------------------- |
| # add X-Request-Id header |
| # ---------------------------------- |
| set $requestId $http_x_request_id; |
| set_secure_random_alphanum $requestId_random 32; |
| set_if_empty $requestId $requestId_random; |
| # add_header X-Request-Id $requestId; |
| proxy_set_header X-Request-Id $requestId; |
| |
| proxy_connect_timeout 10s; # timeout for establishing a connection with a proxied server |
| |
| proxy_read_timeout 10s; # Defines a timeout for reading a response from the proxied server. |
| # The timeout is set only between two successive read operations, |
| # not for the transmission of the whole response. |
| |
| proxy_send_timeout 10s; # Sets a timeout for transmitting a request to the proxied server. |
| # The timeout is set only between two successive write operations, |
| # not for the transmission of the whole request. |
| keepalive_timeout 10s; # timeout during which a keep-alive client connection will stay open on the server side |
| proxy_buffering off; # enables or disables buffering of responses from the proxied server. |
| proxy_http_version 1.1; # Version 1.1 is recommended for use with keepalive connections. |
| proxy_set_header Connection ""; |
| |
| proxy_pass http://$app_name$request_uri; |
| } |
| } |