# Использовать входящий X-Forwarded-Port, если установлено, иначе по умолчанию — 8762.
map $http_x_forwarded_port $final_port {
    default $http_x_forwarded_port;
    ""      8762;
}

map $http_x_forwarded_proto $final_proto {
    default $http_x_forwarded_proto;
    ""      $scheme;
}

server {
  listen 8762;

  # FILE_SIZE_LIMIT — байты в Plane env; nginx хочет размеры m/g.
  # 52428800 байт ≈ 50м
  client_max_body_size 50m;

  port_in_redirect off;
  absolute_redirect off;

  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   $final_proto;
  proxy_set_header X-Forwarded-Host    $host;
  proxy_set_header X-Forwarded-Port    $final_port;

  location /spaces/ {
    proxy_pass http://plane_space_1:3000;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
  }

  location /god-mode/ {
    proxy_pass http://plane_admin_1:3000;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
  }

  location /live/ {
    proxy_pass http://plane_live_1:3000;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
  }

  location /api/ {
    proxy_pass http://plane_api_1:8000;
  }

  location /auth/ {
    proxy_pass http://plane_api_1:8000;
  }

  location /uploads {
    proxy_pass http://plane-minio-1:9000;
  }

  location / {
    proxy_pass http://plane_web_1:3000;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
  }
}
