server {
  listen {{ CS_FRONTEND_HTTP_PORT | last }};
  listen [::]:{{ CS_FRONTEND_HTTP_PORT | last }};

  server_name {{ CS_FRONTEND_PREFIX_ADMIN | last }}.{{ CS_FRONTEND_DOMAIN | last }};

  include /etc/nginx/includes/ssl*conf;

  root /var/www/r7-office/admin;
  index index.html;
  server_tokens off;

  location /
  {
    try_files $uri $uri/ /index.html;
  }

  location /api
  {
    proxy_set_header X-real-ip $remote_addr;
    proxy_set_header X-forward-for $proxy_add_x_forwarded_for;
    proxy_set_header X-Module Admin;
    proxy_pass http://{{ CS_API_HOST | last }}:{{ CS_API_PORT | last }}/api;
    proxy_set_header Host $host;
  }
  
  location /saml2
  {
    proxy_set_header host $host;
    proxy_set_header X-real-ip $remote_addr;
    proxy_set_header X-forward-for $proxy_add_x_forwarded_for;
    proxy_set_header X-Module Admin;
    proxy_pass http://{{ CS_SSO_HOST | last }}:{{ CS_SSO_PORT | last }}/saml2;
  }

  location /web-apps
  {
    proxy_pass {{ DS_FRONTEND_SCHEME | last }}://{{ DS_FRONTEND_PREFIX_DOCSERVER | last }}.{{ DS_FRONTEND_DOMAIN | last }}:{{ DS_FRONTEND_HTTPS_PORT | last }}/web-apps;
  }

#  location /source {
#    proxy_pass http://{{ CS_API_HOST | last }}:{{ CS_API_PORT | last }};
#   proxy_pass {{ CS_FRONTEND_SCHEME | last }}://{{ CS_FRONTEND_PREFIX_CDDISK | last }}.{{ CS_FRONTEND_DOMAIN | last }};
#  }

  location /docserver
  {
    rewrite /docserver/(.*) /$1  break;
    proxy_pass {{ DS_FRONTEND_SCHEME | last }}://{{ DS_FRONTEND_PREFIX_DOCSERVER | last }}.{{ DS_FRONTEND_DOMAIN | last }}:{{ DS_FRONTEND_HTTPS_PORT | last }};
    proxy_redirect     off;
    proxy_set_header   Host $host;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header X-Forwarded-Proto $the_scheme;
    proxy_set_header Connection $proxy_connection;
    proxy_ssl_verify off;
  }

  location /cache
  {
    rewrite /docserver/cache/(.*) /$1  break;
    proxy_pass {{ DS_FRONTEND_SCHEME | last }}://{{ DS_FRONTEND_PREFIX_DOCSERVER | last }}.{{ DS_FRONTEND_DOMAIN | last }}:{{ DS_FRONTEND_HTTPS_PORT | last }};
    proxy_redirect     off;
    proxy_set_header   Host $host;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header X-Forwarded-Proto $the_scheme;
    proxy_set_header Connection $proxy_connection;
    proxy_ssl_verify off;
  }
}
