limit_req_zone $binary_remote_addr zone=public_query:10m rate=20r/m;
limit_req_zone $binary_remote_addr zone=pdf_download:10m rate=30r/m;

server {
  listen 80;
  server_name example.com;
  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl http2;
  server_name example.com;

  ssl_certificate /etc/nginx/certs/fullchain.pem;
  ssl_certificate_key /etc/nginx/certs/privkey.pem;

  client_max_body_size 20m;

  root /usr/share/nginx/html;
  index index.html;

  location /api/public/certificates/search {
    limit_req zone=public_query burst=10 nodelay;
    proxy_pass http://backend:8000/public/certificates/search;
    include /etc/nginx/proxy_params;
  }

  location ~ ^/api/public/certificates/token/.+/download$ {
    limit_req zone=pdf_download burst=10 nodelay;
    proxy_pass http://backend:8000$request_uri;
    rewrite ^/api/(.*)$ /$1 break;
    include /etc/nginx/proxy_params;
  }

  location /api/ {
    proxy_pass http://backend:8000/;
    include /etc/nginx/proxy_params;
  }

  location / {
    try_files $uri $uri/ /index.html;
  }
}
