events {
  worker_connections 768;
}

http {
  include /etc/nginx/mime.types;
  default_type application/octet-stream;

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

  server {
    listen 80;

    keepalive_timeout    70;
    sendfile             on;
    client_max_body_size 0;
    gzip off;

    root /mastodon/public;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";

    location / {
      try_files $uri @proxy;
    }

    location @proxy {
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto https;

      proxy_pass_header Server;

      proxy_pass http://app:3000;
      proxy_buffering off;
      proxy_redirect off;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;

      tcp_nodelay on;
    }

    location /api/v1/streaming {
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto https;

      proxy_pass http://streaming:4000;
      proxy_buffering off;
      proxy_redirect off;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;

      tcp_nodelay on;
    }

    error_page 500 501 502 503 504 /500.html;
  }
}
