server {
  listen 443 ssl http2;
  server_name {{ taiga_public_url | urlsplit('hostname') }};

  large_client_header_buffers 4 32k;
  client_max_body_size {{ taiga_max_upload_file_size }}M;
  charset utf-8;

  # Frontend
  location / {
    alias {{ taiga_root_dir }}/app/front/dist/;
    index index.html;
    try_files $uri $uri/ index.html =404;
  }

  # API
  location /api/ {
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://127.0.0.1:{{ taiga_ports['back'] }}/api/;
    proxy_redirect off;
  }

  # Admin
  location /admin/ {
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://127.0.0.1:{{ taiga_ports['back'] }}/admin/;
    proxy_redirect off;
  }

  # Static files
  location /static/ {
    alias {{ taiga_root_dir }}/app/back/static/;
  }

  # Media
  location /_protected/ {
    internal;
    alias {{ taiga_root_dir }}/data/media/;
    add_header Content-disposition "attachment";
  }

  # Unprotected section
  location /media/exports/ {
    alias {{ taiga_root_dir }}/data/media/exports/;
    add_header Content-disposition "attachment";
  }

  location /media/ {
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://127.0.0.1:{{ taiga_ports['protected'] }}/;
    proxy_redirect off;
  }

  # Events
  location /events {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_connect_timeout 7d;
    proxy_send_timeout 7d;
    proxy_read_timeout 7d;
    proxy_pass http://127.0.0.1:{{ taiga_ports['events'] }}/events;
  }
}
