<% if @onion_address %>
server {
  listen 80;
  server_name mastodon.<%= @onion_address %>;
  include <%= @shared_config_path %>;
}
<% end %>

map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}

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

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

  add_header Strict-Transport-Security "max-age=31536000";
  add_header Onion-Location https://mastodon.<%= @onion_address %>$request_uri;
}
<% end %>

<% if @onion_address %>
server {
  listen 443 ssl http2;
  server_name mastodon.<%= @onion_address %>;
  include <%= @shared_config_path %>;

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

  add_header Strict-Transport-Security "max-age=31536000";
}
<% end %>
