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

    events {
        worker_connections 1024;
    }

    http {
        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        sendfile on;
        keepalive_timeout 65;

        resolver 10.96.0.10 valid=5s ipv6=off;
        resolver_timeout 10s;

        upstream backend {
            zone backend 64k;
            server devops-app-service.devops-demo.svc.cluster.local:80 resolve;
        }

        server {
            listen 80;
            listen [::]:80;
            server_name localhost;

            location / {
                return 301 https://$host$request_uri;
            }
        }

        server {
            listen 443 ssl;
            server_name localhost;

            ssl_certificate     /etc/nginx/certs/tls.crt;
            ssl_certificate_key /etc/nginx/certs/tls.key;

            add_header Strict-Transport-Security "max-age=31536000" always;
            add_header X-Frame-Options SAMEORIGIN;
            add_header X-Content-Type-Options nosniff;

            location / {
                proxy_pass http://backend;

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

                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
            }
        }
    }   