# Generated by Chef
upstream _gitea {
  server   localhost:<%= @upstream_port %>;
}

server {
<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%>
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  server_name <%= @server_name %>;

  ssl_certificate     <%= @ssl_cert %>;
  ssl_certificate_key <%= @ssl_key %>;

  add_header Strict-Transport-Security "max-age=31536000";
<% else -%>
  listen 80;
  server_name <%= @server_name %>;

  location /.well-known {
    root "/var/www/<%= @server_name %>";
  }
<% end -%>

  client_max_body_size 20M;

  location ~ ^/(avatars|repo-avatars)/.*$ {
    proxy_buffers 1024 8k;
    proxy_pass http://_gitea;
    proxy_http_version 1.1;
    expires 30d;
  }

  location / {
    proxy_buffers 1024 8k;
    proxy_pass http://_gitea;
    proxy_http_version 1.1;
  }
}
