upstream berks_api {
  server <%= node[:berkshelf_api][:app_host] %>:<%= node[:berkshelf_api][:port] %> fail_timeout=0;
}

server {
  listen <%= node[:berkshelf_api][:proxy_port] %>;
  server_name <%= node[:berkshelf_api][:host] %>;

<% if node[:berkshelf_api][:proxy][:ssl] then -%>
  ssl on;
  ssl_certificate <%= node[:berkshelf_api][:proxy][:ssl_certificate] %>;
  ssl_certificate_key <%= node[:berkshelf_api][:proxy][:ssl_certificate_key] %>;

<% end -%>
  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    if (!-f $request_filename) {
      proxy_pass http://berks_api;
      break;
    }
  }
}
