worker_processes             1;

error_log                    <%- logDir %>/error.log info;

pid                          <%- tmpDir %>/nginx.pid;

events {
  worker_connections         1024;
}

http {
  include                    mime.types;
  default_type               application/octet-stream;

  sendfile                   on;
  keepalive_timeout          65;
  client_max_body_size       0;
  client_body_temp_path      <%- tmpDir %>/clientBody;
  proxy_temp_path            <%- tmpDir %>/proxy;
  proxy_ssl_server_name      on;<% if (proxyReadTimeout) { %>
  proxy_read_timeout         <%- proxyReadTimeout %>;<% } %>

  log_format                 standard_format
                             '$remote_addr - $remote_user [$time_local] '
                             '"$request" $status $bytes_sent '
                             '"$http_referer" "$http_user_agent" "$gzip_ratio"';
<% if (tls) { %>
  ssl_certificate          server.crt;
  ssl_certificate_key      server.key;
<% } %>
  access_log               <%- logDir %>/access.log standard_format;
  log_not_found            on;
  log_subrequest           on;
<% if (ssi) { %>
  ssi                      on;
  ssi_silent_errors        off;
<% } %><% if (gzip) { %>
  gzip                     on;
  gzip_static              on;
  gzip_min_length          1100;
  gzip_buffers             4 32k;
  gzip_types               text/plain text/css application/javascript text/xml application/xml+rss;
  gzip_vary                on;
  gzip_disable             "MSIE [1-6]\.";
<% } %><% if (extraSite) { %>
<%- extraSite %><% if (standardServer) { %>
<% } %><% } %>
<% if (standardServer) { %>  server {
    listen                   <%- port %><% if (tls) { %> ssl<% } %><% if (http2) { %> http2<% } %>;
    server_name              <%- serverName %>;
<% if (root !== false) { %>
    location / {
      root                   <%- root %>;
      autoindex              <%- directoryIndex ? 'on' : 'off'%>;
      try_files              $uri $uri/index.html <% if (proxy.find(({from, type}) => from === '/' && type === 'http')) { %>@proxy<% } else { %>$uri/ =404<% } %>;
    }
<% } %><% if (stubStatus) { %>
    location /nginx_status {
      stub_status            on;
      access_log             off;

      # only allow local access
      allow                  127.0.0.1;
      deny                   all;
    }
<% } %><% if (proxy.find(({from, type}) => from === '/' && type === 'http') && root !== false) { %>
    location @proxy {
      proxy_pass             <%- proxy.find(({from, type}) => from === '/' && type === 'http').to %>;
      proxy_cache            off;
      proxy_set_header       Host $proxy_host;
      proxy_set_header       X-Real-IP $remote_addr;
      proxy_set_header       X-Forwarded-For $proxy_add_x_forwarded_for;<% if (ssi) { %>
      proxy_set_header       Accept-Encoding "";<% } %><% if (proxy.find(({from, type}) => from === '/' && type === 'http').additionalDirectives) { %>
<%- proxy.find(({from, type}) => from === '/' && type === 'http').additionalDirectives %><% } %>
    }
<% } proxy.filter(({from, type}) => (from !== '/' || root === false) && type === 'http').forEach(({from, to, additionalDirectives}) => { %>
    location <%- from %> {
      proxy_pass             <%- to %>;
      proxy_cache            off;
      proxy_set_header       Host $proxy_host;
      proxy_set_header       X-Real-IP $remote_addr;
      proxy_set_header       X-Forwarded-For $proxy_add_x_forwarded_for;<% if (ssi) { %>
      proxy_set_header       Accept-Encoding "";<% } %><% if (additionalDirectives) { %>
<%- additionalDirectives %><% } %>
    }
<% }); proxy.filter(({type}) => type === 'websocket').forEach(({from, to, additionalDirectives}) => { %>
    location <%- from %> {
      proxy_pass             <%- to %>;
      proxy_cache            off;
      proxy_set_header       Host $proxy_host;
      proxy_http_version     1.1;
      proxy_set_header       Upgrade $http_upgrade;
      proxy_set_header       Connection "upgrade";<% if (additionalDirectives) { %>
<%- additionalDirectives %><% } %>
    }
<% }); proxy.filter(({type}) => type === 'eventsource').forEach(({from, to, additionalDirectives}) => { %>
    location <%- from %> {
      proxy_pass                <%- to %>;
      proxy_cache               off;
      proxy_set_header          Host $proxy_host;
      proxy_http_version        1.1;
      proxy_set_header          Connection "";
      proxy_buffering           off;
      chunked_transfer_encoding off;<% if (additionalDirectives) { %>
<%- additionalDirectives %><% } %>
    }
<% }); %>
    error_page               500 502 503 504 /50x.html;
    location = /50x.html {
      root                   html;
    }
  }
<% } %>}
