server {
  listen 443 ssl; # managed by Certbot
  ssl_certificate /etc/letsencrypt/live/beta.liberama.top/fullchain.pem; # managed by Certbot
  ssl_certificate_key /etc/letsencrypt/live/beta.liberama.top/privkey.pem; # managed by Certbot
  include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

  server_name beta.liberama.top;
  set $liberama http://127.0.0.1:34082;

  client_max_body_size 50m;
  proxy_read_timeout 1h;

  gzip on;
  gzip_min_length 1024;
  gzip_proxied expired no-cache no-store private auth;
  gzip_types *;

  location @liberama {
    proxy_pass $liberama;
  }

  location /api {
    proxy_pass $liberama;
  }

  location /ws {
    proxy_pass $liberama;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 600s;
  }

  location / {
    root /home/beta.liberama/public;

    location /tmp {
      types { } default_type "application/xml; charset=utf-8";
      add_header Content-Encoding gzip;
      try_files $uri @liberama;
    }

    location /upload {
      try_files $uri @liberama;
    }

    location ~* \.(?:manifest|appcache|html)$ {
      expires -1;
    }
  }
}

server {
  listen 80;
  server_name beta.liberama.top;

  return 301 https://$host$request_uri;
}

server {
  listen 80;
  server_name b.beta.liberama.top;
  set $liberama http://127.0.0.1:34082;

  client_max_body_size 50m;
  proxy_read_timeout 1h;

  gzip on;
  gzip_min_length 1024;
  gzip_proxied expired no-cache no-store private auth;
  gzip_types *;

  location @liberama {
    proxy_pass $liberama;
  }

  location /api {
    proxy_pass $liberama;
  }

  location /ws {
    proxy_pass $liberama;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 600s;
  }

  location / {
    root /home/beta.liberama/public;

    location /tmp {
      types { } default_type "application/xml; charset=utf-8";
      add_header Content-Encoding gzip;
      try_files $uri @liberama;
    }

    location /upload {
      try_files $uri @liberama;
    }

    location ~* \.(?:manifest|appcache|html)$ {
      expires -1;
    }
  }
}
