apiVersion: v1
kind: ConfigMap
metadata:
  name: rmt-nginx-vhosts-configmap
data:
  rmt-server-http.conf: |
    upstream rmt {
        server rmt-server-svc:4224;
    }

    server {
        listen 80   default;
        server_name rmt;
        access_log  /var/log/nginx/access.log;
        error_log   /var/log/nginx/error.log;
        root        /usr/share/rmt/public;

        location / {
            # RMT accepts registrations over HTTP and HTTPS by default.
            # If you want to block registrations over HTTP, you can comment out the following try_files line to support HTTPS only.
            try_files $uri/index.html $uri.html $uri @rmt_app;
            autoindex off;
        }

        location /repo {
            autoindex on;
        }

        location = /repo/repoindex.xml {
            # RMT serves /repo/repoindex.xml over HTTP and HTTPS by default.
            # If want to block it over HTTP, you can comment out the following try_files line and uncomment the return
            # statement to redirect all HTTP requests to HTTPS.
            try_files $uri @rmt_app;
            # return 301 https://$host$request_uri;
        }

        location /suma {
            autoindex on;
        }

        location @rmt_app {
            proxy_pass          http://rmt;
            proxy_redirect      off;
            proxy_read_timeout  600;

            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
        }

        # An alias to RMT CA certificate, so that it can be downloaded to client machines.
        location /rmt.crt {
            alias /etc/rmt/ca/rmt-ca.crt;
        }

        # For livenessProbe
        location /index.html {
            alias /srv/www/htdocs/index.html;
        }
    }
  rmt-server-https.conf: |
    server {
        listen 443   ssl;
        server_name rmt;

        access_log  /var/log/nginx/access.log;
        error_log   /var/log/nginx/error.log;
        root        /usr/share/rmt/public;

        ssl_certificate     /etc/rmt/ssl/tls.crt;
        ssl_certificate_key /etc/rmt/ssl/tls.key;
        ssl_protocols       TLSv1.2 TLSv1.3;

        location / {
            try_files $uri/index.html $uri.html $uri @rmt_app;
            autoindex off;
        }

        location /repo {
            autoindex on;
        }

        location = /repo/repoindex.xml {
            try_files $uri @rmt_app;
        }

        location /suma {
            autoindex on;
        }

        location @rmt_app {
            proxy_pass          http://rmt;
            proxy_redirect      off;
            proxy_read_timeout  600;

            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Ssl on;
            proxy_set_header X-Real-IP $remote_addr;
        }

        # An alias to RMT CA certificate, so that it can be downloaded to client machines.
        location /rmt.crt {
            alias /etc/rmt/ca/rmt-ca.crt;
        }

        # For livenessProbe
        location /index.html {
            alias /srv/www/htdocs/index.html;
        }
    }
  
