apiVersion: v1
kind: ConfigMap
metadata:
  name: loadbalancer-config
data:
  nginx.conf: |
    worker_processes 1;

    events { worker_connections 1024; }

    http {

      upstream designer {
        server altinn-designer:5000;
      }

      upstream runtime {
        server altinn-runtime:5005;
      }

      upstream repositories {
        server altinn-repositories:3000;
      }

      upstream grafana {
        server grafana.grafana.svc.cluster.local:80;
      }

      server {
        listen 80;
        server_name altinn.studio;
        # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
        return 301 https://altinn.studio$request_uri;
      }

      server {
        listen 443 ssl http2;

        ssl_protocols TLSv1.1 TLSv1.2;

        ssl_prefer_server_ciphers on;
        ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;

        ssl_certificate /etc/nginx/ssl/altinn_studio/ssl-bundle.crt;
        ssl_certificate_key /etc/nginx/ssl/altinn_studio/altinn.studio.rsa;
        ssl_dhparam /etc/nginx/ssl/altinn_studio/dhparam.pem;

        ssl_stapling on;
        ssl_stapling_verify on;
        ssl_trusted_certificate /etc/nginx/ssl/altinn_studio/ssl-bundle.crt;

        ssl_session_cache   shared:SSL:40m;
        ssl_session_timeout 4h;

        ssl_session_tickets on;

        server_name altinn.studio;

        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

        location = / {
          proxy_pass 			    http://designer/;
          proxy_set_header 	  Host altinn.studio;
          proxy_set_header 	  X-Forwarded-For $remote_addr;
        }

        location /Home/  {
          proxy_pass         	http://designer/Home/;
          proxy_set_header 	  Host altinn.studio;
          proxy_set_header 	  X-Forwarded-For $remote_addr;
        }

        location /designer/ {
          proxy_pass         	http://designer/designer/;
          proxy_set_header 	  Host altinn.studio;
          proxy_set_header 	  X-Forwarded-For $remote_addr;
        }

        location /runtime/ {
          proxy_pass          http://runtime/runtime/;
          proxy_set_header 	  Host altinn.studio;
          proxy_set_header 	  X-Forwarded-For $remote_addr;
        }

        location /designerapi/ {
          proxy_pass          http://designer/designerapi/;
          proxy_set_header  	Host altinn.studio;
          proxy_set_header 	  X-Forwarded-For $remote_addr;
        }

        location / {
          proxy_pass         	http://repositories/;
          proxy_set_header 	  Host altinn.studio;
          proxy_set_header 	  X-Forwarded-For $remote_addr;
        }

        location /grafana/ {
          proxy_pass			    http://grafana/;
          rewrite				      ^/grafana/(.*) /$1 break;
          proxy_set_header	  Host altinn.studio;
          proxy_set_header	  X-Forwarded-For $remote_addr;
        }
      }
    }
