worker_processes auto;
pid /var/log/omnl-bank/nginx.pid;
error_log /var/log/omnl-bank/nginx-error.log;

events {
  worker_connections 1024;
}

http {
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;
  sendfile      on;
  keepalive_timeout 65;

  upstream omnl_lxc_api {
    server 127.0.0.1:3000;
  }

  upstream omnl_lxc_settlement {
    server 127.0.0.1:3011;
  }

  upstream omnl_lxc_exchange {
    server 127.0.0.1:3012;
  }

  server {
    listen 3002 default_server;
    listen [::]:3002 default_server;
    server_name _;

    root /srv/zardasht-portal/frontend-dapp/dist;
    index index.html;

    location /api/v1/ {
      include /srv/zardasht-portal/deploy/nginx/omnl-portal-auth-current.conf.inc;
      proxy_pass http://omnl_lxc_api/api/v1/;
      proxy_http_version 1.1;
      proxy_set_header Host $host;
      proxy_read_timeout 120s;
    }

    location /settlement/ {
      include /srv/zardasht-portal/deploy/nginx/omnl-portal-auth-current.conf.inc;
      proxy_pass http://omnl_lxc_settlement/api/v1/settlement/;
      proxy_http_version 1.1;
      proxy_set_header Host $host;
      proxy_read_timeout 120s;
    }

    location /exchange/ {
      include /srv/zardasht-portal/deploy/nginx/omnl-portal-auth-current.conf.inc;
      proxy_pass http://omnl_lxc_exchange/api/v1/exchange/;
      proxy_http_version 1.1;
      proxy_set_header Host $host;
      proxy_read_timeout 120s;
    }

    location /assets/ {
      expires 1y;
      add_header Cache-Control "public, immutable";
      try_files $uri =404;
    }

    location = /index.html {
      add_header Cache-Control "no-cache, no-store, must-revalidate";
      try_files $uri =404;
    }

    location / {
      add_header Cache-Control "no-cache, no-store, must-revalidate";
      try_files $uri $uri/ /index.html;
    }
  }
}
