user                www-data;
worker_processes    5;
error_log           /var/log/nginx/error.log;

events {
  worker_connections  4096;
}

http {
  include  mime.types;
  index    index.html index.htm;

  log_format   main '$remote_addr - $remote_user [$time_local]  $status '
    '"$request" $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';
  access_log   /var/log/nginx/access.log main;

  server {
    listen       80 default_server;
    server_name _;

    location / {
      resolver        127.0.0.11 valid=30s;
      set             $upstream_catalyst host.docker.internal;
      proxy_pass      http://$upstream_catalyst:8000;
    }

    location /wss {
      resolver        127.0.0.11 valid=30s;
      set             $upstream_catalyst host.docker.internal;
      proxy_pass      http://$upstream_catalyst:8000;

      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_read_timeout 86400;
    }
  }

  server {
    listen       8529 default_server;
    server_name _;

    location / {
      resolver        127.0.0.11 valid=30s;
      set             $upstream_arangodb arangodb;
      proxy_pass      http://$upstream_arangodb:8529;
    }
  }

  server {
    listen       9000 default_server;
    server_name _;

    location / {
      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 $scheme;
      proxy_set_header Host $http_host;

      proxy_connect_timeout 300;
      # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
      proxy_http_version 1.1;
      proxy_set_header Connection "";
      chunked_transfer_encoding off;

      resolver        127.0.0.11 valid=30s;
      set             $upstream_minio minio;
      proxy_pass      http://$upstream_minio:9000;
    }
  }

  server {
    listen       9002 default_server;
    server_name _;

    location / {
      resolver        127.0.0.11 valid=30s;
      set             $upstream_keycloak keycloak;
      proxy_pass      http://$upstream_keycloak:8080;
      proxy_set_header Host               $host;
      proxy_set_header X-Real-IP          $remote_addr;
      proxy_set_header X-Forwarded-Proto  $scheme;
      proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Port   $server_port;
      proxy_set_header X-Forwarded-Host   $host;
      proxy_set_header X-Forwarded-Server $host;
    }
  }

  server {
    listen       9003 default_server;
    server_name _;

    location / {
      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 $scheme;
      proxy_set_header Host $http_host;

      proxy_connect_timeout 300;
      # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
      proxy_http_version 1.1;
      proxy_set_header Connection "";
      chunked_transfer_encoding off;

      resolver        127.0.0.11 valid=30s;
      set             $upstream_minio minio;
      proxy_pass      http://$upstream_minio:9003;
    }
  }
}
