map $http_upgrade $type {
  default "web";
  websocket "ws";
}

server {
  listen 80 default;
  server_name _;
  root /app/public;

  index index.php;

  location / { try_files /i-should-not-exist @$type; }

  location @web { try_files $uri $uri/ @octane; }

  location = /favicon.ico { access_log off; log_not_found off; }
  location = /robots.txt  { access_log off; log_not_found off; }

  location @ws {
    proxy_set_header Host $http_host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_cache_bypass $http_upgrade;
    proxy_http_version 1.1;
    proxy_redirect off;

    proxy_pass http://127.0.0.1:8080;
  }

  location @octane {
    proxy_send_timeout 300;
    proxy_read_timeout 300;

    client_max_body_size 512M;
    client_body_temp_path /tmp;

    proxy_set_header Host $http_host;
    proxy_set_header SERVER_PORT $server_port;
    proxy_set_header REMOTE_ADDR $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_pass http://127.0.0.1:8090$uri?$query_string;
  }

  location ~ \.php$ {
    proxy_send_timeout 300;
    proxy_read_timeout 300;

    client_max_body_size 512M;
    client_body_temp_path /tmp;

    proxy_set_header Host $http_host;
    proxy_set_header SERVER_PORT $server_port;
    proxy_set_header REMOTE_ADDR $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_pass http://127.0.0.1:8090$uri?$query_string;
  }
}
