user  nginx;
worker_processes  1;

events {
  worker_connections  1024;
}
http {
  include           mime.types;

  gzip              on;
  gzip_proxied      any;
  gzip_http_version 1.1;
  gzip_comp_level   6;
  gzip_types        text/plain text/css text/javascript application/json application/x-javascript text/xml application/xml application/xml+rss;
  gzip_disable      msie6;

  upstream  exo_app {
    server  exo:8080;
  }

  upstream  chatserver {
    server  chatserver:8080;
  }

  server {
    listen 80 default_server;
    #server_name my.server.name;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    client_max_body_size 250m;

    #### eXo Platform
    location / {
      proxy_pass http://exo_app;
      # Pass the client informations the the backend
    }
    # we limit the file upload size (this upload url is the one for File Explorer)
    location /portal/rest/wcmDriver/uploadFile/upload {
      proxy_pass http://exo_app;
      # we define a max body size to allow file upload
      # Disable nginx buffering and enforce http 1.1 (ITOP-3253)
      # source: https://serverfault.com/questions/768693/nginx-how-to-completely-disable-request-body-buffering
        proxy_http_version 1.1;
      proxy_request_buffering off;
    }
    # we limit the file upload size (this upload url is the one for file selector upload used in the activity stream)
    location /portal/rest/managedocument/uploadFile/upload {
      proxy_pass http://exo_app;
      # we define a max body size to allow file upload
      # Disable nginx buffering and enforce http 1.1 (ITOP-3253)
      # source: https://serverfault.com/questions/768693/nginx-how-to-completely-disable-request-body-buffering
        proxy_http_version 1.1;
      proxy_request_buffering off;
    }
    # we limit the portal upload to 5m for user and space avatar upload
    location /portal/upload {
      proxy_pass http://exo_app;
        client_max_body_size 5m;
      # Disable nginx buffering and enforce http 1.1 (ITOP-3253)
      # source: https://serverfault.com/questions/768693/nginx-how-to-completely-disable-request-body-buffering
      proxy_http_version 1.1;
      proxy_request_buffering off;
    }
    # Websocket for Cometd
    location /cometd/cometd {
      proxy_pass http://exo:8080;
        proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }
    # standalone chat server configuration
    location /chatServer {
      proxy_pass http://chatserver;
      # Disable nginx buffering and enforce http 1.1 (ITOP-3253)
      # source: https://serverfault.com/questions/768693/nginx-how-to-completely-disable-request-body-buffering
        proxy_http_version 1.1;
      proxy_request_buffering off;
    }
    # Websocket for Cometd
    location /chatServer/cometd {
      proxy_pass http://chatserver;
        proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }


    #### MailHug
    # Mail IHM
    location /mail {
      proxy_pass http://mail:8025;
    }
    # Websocket
    location /mail/api/v2/websocket {
      proxy_pass http://mail:8025;
        proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }
  }
}
