github.com/technosophos/deis@v1.7.1-0.20150915173815-f9005256004b/router/rootfs/etc/confd/templates/nginx.conf (about)

     1  # required to run in a container
     2  daemon off;
     3  
     4  user nginx;
     5  worker_processes {{ or (getv "/deis/router/workerProcesses") "auto" }};
     6  pid /run/nginx.pid;
     7  
     8  events {
     9      worker_connections {{ or (getv "/deis/router/maxWorkerConnections") "768" }};
    10      # multi_accept on;
    11  }
    12  
    13  
    14  http {
    15      # basic settings
    16      vhost_traffic_status_zone;
    17  
    18      sendfile on;
    19      tcp_nopush on;
    20      tcp_nodelay on;
    21  
    22      # The Timeout value must be greater than the front facing load balancers timeout value.
    23      # Default is the deis recommended timeout value for ELB - 1200 seconds + 100s extra.
    24      {{ $defaultTimeout := or (getv "/deis/router/defaultTimeout") "1300" }}
    25      keepalive_timeout {{ $defaultTimeout }};
    26  
    27      types_hash_max_size 2048;
    28      server_names_hash_max_size {{ or (getv "/deis/router/serverNameHashMaxSize") "512" }};
    29      server_names_hash_bucket_size {{ or (getv "/deis/router/serverNameHashBucketSize") "64" }};
    30  
    31      include /opt/nginx/conf/mime.types;
    32      default_type application/octet-stream;
    33      {{ if exists "/deis/router/gzip" }}
    34      gzip {{ getv "/deis/router/gzip" }};
    35      gzip_comp_level {{ or (getv "/deis/router/gzipCompLevel") "5" }};
    36      gzip_disable {{ or (getv "/deis/router/gzipDisable") "\"msie6\"" }};
    37      gzip_http_version {{ or (getv "/deis/router/gzipHttpVersion") "1.1" }};
    38      gzip_min_length {{ or (getv "/deis/router/gzipMinLength") "256" }};
    39      gzip_types {{ or (getv "/deis/router/gzipTypes") "application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component" }};
    40      gzip_proxied {{ or (getv "/deis/router/gzipProxied") "any" }};
    41      gzip_vary {{ or (getv "/deis/router/gzipVary") "on" }};
    42      {{ end }}
    43  
    44      {{ $useFirewall := or (getv "/deis/router/firewall/enabled") "false" }}{{ if eq $useFirewall "true" }}# include naxsi rules
    45      include     /opt/nginx/firewall/naxsi_core.rules;
    46      include     /opt/nginx/firewall/web_apps.rules;
    47      include     /opt/nginx/firewall/scanner.rules;
    48      include     /opt/nginx/firewall/web_server.rules;{{ end }}
    49      {{ $firewallErrorCode := or (getv "/deis/router/firewall/errorCode") "400" }}
    50      client_max_body_size "{{ or (getv "/deis/router/bodySize") "1m" }}";
    51  
    52      {{ $useProxyProtocol := or (getv "/deis/router/proxyProtocol") "false" }}{{ if ne $useProxyProtocol "false" }}
    53      set_real_ip_from {{ or (getv "/deis/router/proxyRealIpCidr") "10.0.0.0/8" }};
    54      real_ip_header proxy_protocol;
    55      {{ end }}
    56  
    57      log_format upstreaminfo '[$time_local] - {{ if ne $useProxyProtocol "false" }}$proxy_protocol_addr{{ else }}$remote_addr{{ end }} - $remote_user - $status - "$request" - $bytes_sent - "$http_referer" - "$http_user_agent" - "$server_name" - $upstream_addr - $http_host - $upstream_response_time - $request_time';
    58  
    59      # send logs to STDOUT so they can be seen using 'docker logs'
    60      access_log /opt/nginx/logs/access.log upstreaminfo;
    61      error_log  /opt/nginx/logs/error.log {{ or (getv "/deis/router/errorLogLevel") "error" }};
    62  
    63      map $http_upgrade $connection_upgrade {
    64          default upgrade;
    65          ''      close;
    66      }
    67  
    68      # trust http_x_forwarded_proto headers correctly indicate ssl offloading
    69      map $http_x_forwarded_proto $access_scheme {
    70        default $http_x_forwarded_proto;
    71        ''      $scheme;
    72      }
    73  
    74      ## HSTS instructs the browser to replace all HTTP links with HTTPS links for this domain until maxAge seconds from now
    75      {{ $enableHSTS := or (getv "/deis/router/hsts/enabled") "false" }}
    76      {{ $maxAgeHSTS := or (getv "/deis/router/hsts/maxAge") "10886400" }}
    77      {{ $includeSubdomainsHSTS := or (getv "/deis/router/hsts/includeSubDomains") "false" }}
    78      {{ $preloadHSTS := or (getv "/deis/router/hsts/preload") "false" }}
    79      map $access_scheme $sts {
    80        'https' 'max-age={{ $maxAgeHSTS }}{{ if eq $includeSubdomainsHSTS "true" }}; includeSubDomains{{ end }}{{ if eq $preloadHSTS "true" }}; preload{{ end }}';
    81      }
    82  
    83      ## since HSTS headers are not permitted on HTTP requests, 301 redirects to HTTPS resources are also necessary
    84      {{ $enforceHTTPS := or (getv "/deis/router/enforceHTTPS") $enableHSTS "false" }}
    85  
    86      {{/* Enabling the enforceWhitelist option deny all connections except those from IPs explicitly allowed */}}
    87      {{ $enforceWhitelist := or (getv "/deis/router/enforceWhitelist") "false" }}
    88  
    89      ## start deis-controller
    90      {{ if exists "/deis/controller/host" }}
    91      upstream deis-controller {
    92          server {{ getv "/deis/controller/host" }}:{{ getv "/deis/controller/port" }};
    93      }
    94      {{ end }}
    95  
    96      server {
    97          server_name ~^{{ or (getv "/deis/controller/subdomain") "deis" }}\.(?<domain>.+)$;
    98          include deis.conf;
    99  
   100          {{/* IP Whitelisting */}}
   101          {{ $controllerHasWhitelist := exists "/deis/router/controller/whitelist" }}
   102          {{ if $controllerHasWhitelist }}
   103          ## Only connections from the following addresses are allowed
   104          {{ $whitelist := getv "/deis/router/controller/whitelist" }}
   105          {{ range $whitelist_entry := split $whitelist "," }}
   106          {{ $whitelist_detail := split $whitelist_entry ":" }}
   107          allow {{index $whitelist_detail 0}};{{if eq (len $whitelist_detail) 2}}  # {{index $whitelist_detail 1}}{{ end }}
   108          {{ end }}
   109          {{ end }}
   110          {{ if or (eq $enforceWhitelist "true") $controllerHasWhitelist }}
   111          deny all;
   112          {{ end }}
   113  
   114          {{ if exists "/deis/controller/host" }}
   115          location / {
   116              {{ if eq $useFirewall "true" }}include                     /opt/nginx/firewall/active-mode.rules;{{ end }}
   117              proxy_buffering             off;
   118              proxy_set_header            Host $host;
   119              {{ if ne $useProxyProtocol "false" }}
   120              proxy_set_header            X-Forwarded-For $proxy_protocol_addr;
   121              {{ else }}
   122              proxy_set_header            X-Forwarded-For $proxy_add_x_forwarded_for;
   123              {{ end }}
   124              proxy_redirect              off;
   125              proxy_connect_timeout       {{ or (getv "/deis/router/controller/timeout/connect") "10s" }};
   126              proxy_send_timeout          {{ or (getv "/deis/router/controller/timeout/send") "20m" }};
   127              proxy_read_timeout          {{ or (getv "/deis/router/controller/timeout/read") "20m" }};
   128  
   129              proxy_pass                  http://deis-controller;
   130          }
   131          {{ else }}
   132          location / {
   133              return 503;
   134          }
   135          {{ end }}
   136  
   137          {{ if eq $useFirewall "true" }}location /RequestDenied {
   138              return {{ $firewallErrorCode }};
   139          }
   140          {{ end }}
   141  
   142          {{ if eq $enforceHTTPS "true" }}
   143          if ($access_scheme != "https") {
   144            return 301 https://$host$request_uri;
   145          }
   146          {{ end }}
   147  
   148          {{ if eq $enableHSTS "true" }}
   149          add_header Strict-Transport-Security $sts always;
   150          {{ end }}
   151      }
   152      ## end deis-controller
   153  
   154      ## start deis-store-gateway
   155      {{ if exists "/deis/store/gateway/host" }}
   156      upstream deis-store-gateway {
   157          server {{ getv "/deis/store/gateway/host" }}:{{ getv "/deis/store/gateway/port" }};
   158      }
   159      {{ end }}
   160  
   161      server {
   162          server_name ~^deis-store\.(?<domain>.+)$;
   163          include deis.conf;
   164  
   165          client_max_body_size            0;
   166  
   167          {{ if exists "/deis/store/gateway/host" }}
   168          location / {
   169              {{ if eq $useFirewall "true" }}include                     /opt/nginx/firewall/active-mode.rules;{{ end }}
   170              proxy_buffering             off;
   171              proxy_set_header            Host $host;
   172              {{ if ne $useProxyProtocol "false" }}
   173              proxy_set_header            X-Forwarded-For $proxy_protocol_addr;
   174              {{ else }}
   175              proxy_set_header            X-Forwarded-For $proxy_add_x_forwarded_for;
   176              {{ end }}
   177              proxy_redirect              off;
   178              proxy_connect_timeout       10s;
   179              proxy_send_timeout          {{ $defaultTimeout }}s;
   180              proxy_read_timeout          {{ $defaultTimeout }}s;
   181  
   182              proxy_pass                  http://deis-store-gateway;
   183          }
   184          {{ else }}
   185          location / {
   186              return 503;
   187          }
   188          {{ end }}
   189      }
   190      ## end deis-store-gateway
   191      {{ $useSSL := or (getv "/deis/router/sslCert") "false" }}
   192      {{ $domains := ls "/deis/domains" }}
   193      {{ $certs := ls "/deis/certs" }}
   194      ## start service definitions for each application
   195      {{ range $app := lsdir "/deis/services" }}
   196      {{ $upstreams := printf "/deis/services/%s/*" $app}}
   197      upstream {{ $app }} {
   198          {{ if exists "/deis/router/affinityArg" }}
   199          hash $arg_{{ getv "/deis/router/affinityArg" }} consistent;
   200          {{ end }}
   201          {{ range gets $upstreams }}server {{ .Value }};
   202          {{ end }}
   203      }
   204      {{ $appContainers := gets $upstreams }}{{ $appContainerLen := len $appContainers }}
   205      ## server entries for custom domains
   206      {{ range $app_domain := $domains }}{{ if eq $app (getv (printf "/deis/domains/%s" $app_domain)) }}
   207      server {
   208          server_name {{ $app_domain }};
   209          {{/* if a SSL certificate is installed for this domain, use SSL */}}
   210          {{/* NOTE (bacongobbler): domains are separate from the default platform domain, */}}
   211          {{/* so we can't rely on deis.conf as each domain is an island */}}
   212          {{ if exists (printf "/deis/certs/%s/cert" $app_domain) }}
   213          server_name_in_redirect off;
   214          port_in_redirect off;
   215          listen 80{{ if ne $useProxyProtocol "false" }} proxy_protocol{{ end }};
   216          listen 443 ssl spdy{{ if ne $useProxyProtocol "false" }} proxy_protocol{{ end }};
   217          ssl_certificate /etc/ssl/deis/certs/{{ $app_domain }}.cert;
   218          ssl_certificate_key /etc/ssl/deis/keys/{{ $app_domain }}.key;
   219          include ssl.conf;
   220          {{/* if there's no app SSL cert but we have a router SSL cert, enable that instead */}}
   221          {{/* TODO (bacongobbler): wait for https://github.com/kelseyhightower/confd/issues/270 */}}
   222          {{/* so we can apply this config to just subdomains of the platform domain. */}}
   223          {{/* ref: https://github.com/deis/deis/pull/3519 */}}
   224          {{ else }}
   225          include deis.conf;
   226          {{ end }}
   227  
   228          {{/* IP Whitelisting */}}
   229          {{ $appHasWhitelist := exists (printf "/deis/config/%s/deis_whitelist" $app) }}
   230          {{ if $appHasWhitelist }}
   231          ## Only connections from the following addresses are allowed
   232          {{ $whitelist := getv (printf "/deis/config/%s/deis_whitelist" $app) }}
   233          {{ range $whitelist_entry := split $whitelist "," }}
   234          {{ $whitelist_detail := split $whitelist_entry ":" }}
   235          allow {{index $whitelist_detail 0}};{{if eq (len $whitelist_detail) 2}}  # {{index $whitelist_detail 1}}{{ end }}
   236          {{ end }}
   237          {{ end }}
   238          {{ if or (eq $enforceWhitelist "true") $appHasWhitelist}}
   239          deny all;
   240          {{ end }}
   241  
   242          {{ if ne $appContainerLen 0 }}
   243          location / {
   244              {{ if eq $useFirewall "true" }}include                     /opt/nginx/firewall/active-mode.rules;{{ end }}
   245              proxy_buffering             off;
   246              proxy_set_header            Host $host;
   247              set $access_ssl 'off';
   248              set $access_port '80';
   249              if ($access_scheme ~ https) {
   250                  set $access_ssl 'on';
   251                  set $access_port '443';
   252              }
   253              proxy_set_header            X-Forwarded-Port  $access_port;
   254              proxy_set_header            X-Forwarded-Proto $access_scheme;
   255              {{ if ne $useProxyProtocol "false" }}
   256              proxy_set_header            X-Forwarded-For   $proxy_protocol_addr;
   257              {{ else }}
   258              proxy_set_header            X-Forwarded-For   $proxy_add_x_forwarded_for;
   259              {{ end }}
   260              proxy_set_header            X-Forwarded-Ssl   $access_ssl;
   261              proxy_redirect              off;
   262              proxy_connect_timeout       30s;
   263              proxy_send_timeout          {{ $defaultTimeout }}s;
   264              proxy_read_timeout          {{ $defaultTimeout }}s;
   265              proxy_http_version          1.1;
   266              proxy_set_header            Upgrade           $http_upgrade;
   267              proxy_set_header            Connection        $connection_upgrade;
   268  
   269              proxy_next_upstream         error timeout http_502 http_503 http_504;
   270  
   271              {{ if eq $enforceHTTPS "true" }}
   272              if ($access_scheme != "https") {
   273                return 301 https://$host$request_uri;
   274              }
   275              {{ end }}
   276  
   277              {{ if eq $enableHSTS "true" }}
   278              add_header Strict-Transport-Security $sts always;
   279              {{ end }}
   280  
   281              ## workaround for nginx hashing empty string bug http://trac.nginx.org/nginx/ticket/765
   282              {{ if exists "/deis/router/affinityArg" }}
   283              set_random $prng 0 99;
   284              set_if_empty $arg_{{ getv "/deis/router/affinityArg" }} $prng;
   285              {{ end }}
   286  
   287              proxy_pass                  http://{{ $app }};
   288          }
   289          {{ else }}
   290          location / {
   291              return 503;
   292          }
   293          {{ end }}
   294          {{ if eq $useFirewall "true" }}location /RequestDenied {
   295              return {{ $firewallErrorCode }};
   296          }
   297          {{ end }}
   298      }{{ end }}{{ end }}
   299      ## end entries for custom domains
   300  
   301      server {
   302          server_name ~^{{ $app }}\.(?<domain>.+)$;
   303          include deis.conf;
   304  
   305          {{/* IP Whitelisting */}}
   306          {{ $appHasWhitelist := exists (printf "/deis/config/%s/deis_whitelist" $app) }}
   307          {{ if $appHasWhitelist }}
   308          ## Only connections from the following addresses are allowed
   309          {{ $whitelist := getv (printf "/deis/config/%s/deis_whitelist" $app) }}
   310          {{ range $whitelist_entry := split $whitelist "," }}
   311          {{ $whitelist_detail := split $whitelist_entry ":" }}
   312          allow {{index $whitelist_detail 0}};{{if eq (len $whitelist_detail) 2}}  # {{index $whitelist_detail 1}}{{ end }}
   313          {{ end }}
   314          {{ end }}
   315          {{ if or (eq $enforceWhitelist "true") $appHasWhitelist}}
   316          deny all;
   317          {{ end }}
   318  
   319          {{ if ne $appContainerLen 0 }}
   320          location / {
   321              {{ if eq $useFirewall "true" }}include                     /opt/nginx/firewall/active-mode.rules;{{ end }}
   322              proxy_buffering             off;
   323              proxy_set_header            Host $host;
   324              set $access_ssl 'off';
   325              set $access_port '80';
   326              if ($access_scheme ~ https) {
   327                  set $access_ssl 'on';
   328                  set $access_port '443';
   329              }
   330              proxy_set_header            X-Forwarded-Port  $access_port;
   331              proxy_set_header            X-Forwarded-Proto $access_scheme;
   332              {{ if ne $useProxyProtocol "false" }}
   333              proxy_set_header            X-Forwarded-For   $proxy_protocol_addr;
   334              {{ else }}
   335              proxy_set_header            X-Forwarded-For   $proxy_add_x_forwarded_for;
   336              {{ end }}
   337              proxy_set_header            X-Forwarded-Ssl   $access_ssl;
   338              proxy_redirect              off;
   339              proxy_connect_timeout       30s;
   340              proxy_send_timeout          {{ $defaultTimeout }}s;
   341              proxy_read_timeout          {{ $defaultTimeout }}s;
   342              proxy_http_version          1.1;
   343              proxy_set_header            Upgrade           $http_upgrade;
   344              proxy_set_header            Connection        $connection_upgrade;
   345  
   346              proxy_next_upstream         error timeout http_502 http_503 http_504;
   347  
   348              {{ if eq $enforceHTTPS "true" }}
   349              if ($access_scheme != "https") {
   350                return 301 https://$host$request_uri;
   351              }
   352              {{ end }}
   353  
   354              {{ if eq $enableHSTS "true" }}
   355              add_header Strict-Transport-Security $sts always;
   356              {{ end }}
   357  
   358              proxy_pass                  http://{{ $app }};
   359          }
   360          {{ else }}
   361          location / {
   362              return 503;
   363          }
   364          {{ end }}
   365          {{ if eq $useFirewall "true" }}location /RequestDenied {
   366              return {{ $firewallErrorCode }};
   367          }
   368          {{ end }}
   369      }{{ end }}
   370      ## end service definitions for each application
   371  
   372      # healthcheck
   373      server {
   374          listen 80 default_server reuseport{{ if ne $useProxyProtocol "false" }} proxy_protocol{{ end }};
   375          location /health-check {
   376              default_type 'text/plain';
   377              access_log off;
   378              return 200;
   379          }
   380          location /router-nginx-status {
   381              vhost_traffic_status_display;
   382              vhost_traffic_status_display_format html;
   383          }
   384          location / {
   385              return 404;
   386          }
   387      }
   388      #start k8s apps
   389      {{ range $k8namespace := lsdir "/registry/services/specs/" }}
   390      {{ $k8appdir := printf "/registry/services/specs/%s" $k8namespace}}{{ range $kapp := ls $k8appdir }}
   391      {{ $k8appPath := printf "/registry/services/specs/%s/%s" $k8namespace $kapp}}{{ $k8Svc := json (getv $k8appPath) }}
   392      {{ $upstreams := printf "/registry/services/specs/%s/%s" $k8namespace $kapp}}
   393      upstream {{ if $k8Svc.metadata.labels.name }}{{ $k8Svc.metadata.labels.name }}{{ else }}{{ $k8Svc.metadata.name }}{{ end }} {
   394          {{ if exists "/deis/router/affinityArg" }}
   395          hash $arg_{{ getv "/deis/router/affinityArg" }} consistent;
   396          {{ end }}
   397          server {{ $k8Svc.spec.clusterIP }}:80;
   398      }
   399      {{ $appContainers := gets $upstreams }}{{ $appContainerLen := len $appContainers }}
   400      {{ $k8sappname := or $k8Svc.metadata.labels.name $k8Svc.metadata.name }}
   401      ## server entries for custom domains
   402      {{ range $app_domain := $domains }}{{ if eq $k8sappname (getv (printf "/deis/domains/%s" $app_domain)) }}
   403      server {
   404          server_name {{ $app_domain }};
   405          {{/* if a SSL certificate is installed for this domain, use SSL */}}
   406          {{/* NOTE (bacongobbler): domains are separate from the default platform domain, */}}
   407          {{/* so we can't rely on deis.conf as each domain is an island */}}
   408          {{ if exists (printf "/deis/certs/%s/cert" $app_domain) }}
   409          server_name_in_redirect off;
   410          port_in_redirect off;
   411          listen 80{{ if ne $useProxyProtocol "false" }} proxy_protocol{{ end }};
   412          listen 443 ssl spdy{{ if ne $useProxyProtocol "false" }} proxy_protocol{{ end }};
   413          ssl_certificate /etc/ssl/deis/certs/{{ $app_domain }}.cert;
   414          ssl_certificate_key /etc/ssl/deis/keys/{{ $app_domain }}.key;
   415          include ssl.conf;
   416          {{/* if there's no app SSL cert but we have a router SSL cert, enable that instead */}}
   417          {{/* TODO (bacongobbler): wait for https://github.com/kelseyhightower/confd/issues/270 */}}
   418          {{/* so we can apply this config to just subdomains of the platform domain. */}}
   419          {{/* ref: https://github.com/deis/deis/pull/3519 */}}
   420          {{ else }}
   421          include deis.conf;
   422          {{ end }}
   423          {{ if ne $appContainerLen 0 }}
   424          location / {
   425              {{ if eq $useFirewall "true" }}include                     /opt/nginx/firewall/active-mode.rules;{{ end }}
   426              proxy_buffering             off;
   427              proxy_set_header            Host $host;
   428              set $access_ssl 'off';
   429              set $access_port '80';
   430              if ($access_scheme ~ https) {
   431                  set $access_ssl 'on';
   432                  set $access_port '443';
   433              }
   434              proxy_set_header            X-Forwarded-Port  $access_port;
   435              proxy_set_header            X-Forwarded-Proto $access_scheme;
   436              {{ if ne $useProxyProtocol "false" }}
   437              proxy_set_header            X-Forwarded-For   $proxy_protocol_addr;
   438              {{ else }}
   439              proxy_set_header            X-Forwarded-For   $proxy_add_x_forwarded_for;
   440              {{ end }}
   441              proxy_set_header            X-Forwarded-Ssl   $access_ssl;
   442              proxy_redirect              off;
   443              proxy_connect_timeout       30s;
   444              proxy_send_timeout          {{ $defaultTimeout }}s;
   445              proxy_read_timeout          {{ $defaultTimeout }}s;
   446              proxy_http_version          1.1;
   447              proxy_set_header            Upgrade           $http_upgrade;
   448              proxy_set_header            Connection        $connection_upgrade;
   449  
   450              proxy_next_upstream         error timeout http_502 http_503 http_504;
   451  
   452              {{ if eq $enforceHTTPS "true" }}
   453              if ($access_scheme != "https") {
   454                return 301 https://$host$request_uri;
   455              }
   456              {{ end }}
   457  
   458              {{ if eq $enableHSTS "true" }}
   459              add_header Strict-Transport-Security $sts always;
   460              {{ end }}
   461  
   462              ## workaround for nginx hashing empty string bug http://trac.nginx.org/nginx/ticket/765
   463              {{ if exists "/deis/router/affinityArg" }}
   464              set_random $prng 0 99;
   465              set_if_empty $arg_{{ getv "/deis/router/affinityArg" }} $prng;
   466              {{ end }}
   467  
   468              proxy_pass                  http://{{ if $k8Svc.metadata.labels.name }}{{ $k8Svc.metadata.labels.name }}{{ else }}{{ $k8Svc.metadata.name }}{{ end }};
   469          }
   470          {{ else }}
   471          location / {
   472              return 503;
   473          }
   474          {{ end }}
   475          {{ if eq $useFirewall "true" }}location /RequestDenied {
   476              return {{ $firewallErrorCode }};
   477          }
   478          {{ end }}
   479      }{{ end }}{{ end }}
   480      ## end entries for custom domains
   481  
   482      server {
   483          server_name ~^{{ if $k8Svc.metadata.labels.name }}{{ $k8Svc.metadata.labels.name }}{{ else }}{{ $k8Svc.metadata.name }}{{ end }}\.(?<domain>.+)$;
   484          include deis.conf;
   485          {{ if ne $appContainerLen 0 }}
   486          location / {
   487              {{ if eq $useFirewall "true" }}include                     /opt/nginx/firewall/active-mode.rules;{{ end }}
   488              proxy_buffering             off;
   489              proxy_set_header            Host $host;
   490              set $access_ssl 'off';
   491              set $access_port '80';
   492              if ($access_scheme ~ https) {
   493                  set $access_ssl 'on';
   494                  set $access_port '443';
   495              }
   496              proxy_set_header            X-Forwarded-Port  $access_port;
   497              proxy_set_header            X-Forwarded-Proto $access_scheme;
   498              {{ if ne $useProxyProtocol "false" }}
   499              proxy_set_header            X-Forwarded-For   $proxy_protocol_addr;
   500              {{ else }}
   501              proxy_set_header            X-Forwarded-For   $proxy_add_x_forwarded_for;
   502              {{ end }}
   503              proxy_set_header            X-Forwarded-Ssl   $access_ssl;
   504              proxy_redirect              off;
   505              proxy_connect_timeout       30s;
   506              proxy_send_timeout          {{ $defaultTimeout }}s;
   507              proxy_read_timeout          {{ $defaultTimeout }}s;
   508              proxy_http_version          1.1;
   509              proxy_set_header            Upgrade           $http_upgrade;
   510              proxy_set_header            Connection        $connection_upgrade;
   511  
   512              proxy_next_upstream         error timeout http_502 http_503 http_504;
   513  
   514              {{ if eq $enforceHTTPS "true" }}
   515              if ($access_scheme != "https") {
   516                return 301 https://$host$request_uri;
   517              }
   518              {{ end }}
   519  
   520              {{ if eq $enableHSTS "true" }}
   521              add_header Strict-Transport-Security $sts always;
   522              {{ end }}
   523  
   524              proxy_pass                  http://{{ if $k8Svc.metadata.labels.name }}{{ $k8Svc.metadata.labels.name }}{{ else }}{{ $k8Svc.metadata.name }}{{ end }};
   525          }
   526          {{ else }}
   527          location / {
   528              return 503;
   529          }
   530          {{ end }}
   531          {{ if eq $useFirewall "true" }}location /RequestDenied {
   532              return {{ $firewallErrorCode }};
   533          }
   534          {{ end }}
   535      }{{end}}{{end}}
   536  }
   537  
   538  ## start builder
   539  {{ if exists "/deis/builder/host" }}
   540  stream {
   541  
   542      upstream builder {
   543          server {{ getv "/deis/builder/host" }}:{{ getv "/deis/builder/port" }};
   544      }
   545  
   546      server {
   547          listen 2222;
   548          proxy_connect_timeout  {{ or (getv "/deis/router/builder/timeout/connect") "10000" }};
   549          proxy_timeout          {{ or (getv "/deis/router/builder/timeout/tcp") "1200000" }};
   550          proxy_pass builder;
   551      }
   552  }{{ end }}
   553  ## end builder