<%
ssl_enabled = node['nexus-grid']['with_ssl_cert_cookbook']
context_path = @nexus_ver == '3' ? '/' : '/nexus'
-%>
worker_processes 1;

events {
  worker_connections 1024;
}

http {
  sendfile on;

  upstream docker-nexus {
    server nexus:8081;
  }

  server {
<% if ssl_enabled %>
    listen 8081 default ssl;
    ssl on;
    ssl_certificate      /root/server.crt;
    ssl_certificate_key  /root/server.key;
<% else %>
    listen 8081;
<% end %>

    location <%= context_path %> {
      proxy_pass         http://docker-nexus<%= context_path %>;
      proxy_redirect     off;
      proxy_set_header   Host $http_host;  # $host does not include the port number.
      proxy_set_header   X-Real-IP $remote_addr;
<% if ssl_enabled %>
      proxy_set_header   X-Forwarded-Proto https;
<% end %>
      proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header   X-Forwarded-Host $server_name;
    }
  }
}
