apiVersion: v1
kind: ConfigMap
metadata:
  name: project-proxy-nginx-config
data:
  nginx.conf: |
    user  nginx;
    worker_processes  1;
    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;
    events {
        worker_connections  1024;
    }
    http {
      include       /etc/nginx/mime.types;
      default_type  application/octet-stream;
      log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
      access_log  /var/log/nginx/access.log  main;
      sendfile        on;
      keepalive_timeout  65;

      server {
        listen 9000;
        resolver kube-dns.kube-system.svc.cluster.local valid=5s;
        client_max_body_size 1000000M;

        location = /auth {
            internal;
            proxy_pass              http://127.0.0.1:8080/api/auth/project;
            proxy_pass_request_body off;
            proxy_set_header        Content-Length "";
            proxy_set_header        X-Original-URI $request_uri;
        }

        location ~ ^/mlflow/([^/]+)/(.*)$ {
            auth_request /auth;
            auth_request_set $auth_status $upstream_status;
            proxy_pass http://$1-mlflow.kdl.svc.cluster.local:5000/$2$is_args$args;
        }

        location ~ ^/filebrowser/([^/]+)/(.*)$ {
            auth_request /auth;
            auth_request_set $auth_status $upstream_status;
            proxy_pass http://$1-filebrowser.kdl.svc.cluster.local:9696/$2$is_args$args;
        }
      }
    }
