apiVersion: v1
kind: ConfigMap
metadata:
  name: {{k8s_deploy.name}}-etc
  namespace: {{k8s_deploy.namespace}}
data:
  nginx.conf: |
      user nginx;
      # Set to number of CPU cores, auto will try to autodetect.
      worker_processes auto;
      # Maximum open file descriptors per process. Should be greater than worker_connections.
      worker_rlimit_nofile 8192;
      events {
        # Set the maximum number of connection each worker process can open. Anything higher than this
        # will require Unix optimisations.
        worker_connections 8000;

        # Accept all new connections as they're opened.
        multi_accept on;
      }
      http {
        # HTTP
        #include global/http.conf;
        # MIME Types
        include mime.types;
        default_type application/octet-stream;
        # Limits & Timeouts
        #include global/limits.conf;
        # Specifies the main log format.
        #log_format main '$http_x_real_ip - $real_ip_header - $http_x_forwarder_for - $http_x_real_ip - $remote_addr - $remote_user [$time_local] "$request" '
        log_format main '$http_x_real_ip - $http_x_forwarder_for - $http_x_real_ip - $remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" ';
        # Default Logs
        error_log /var/log/nginx/error.log warn;
        access_log /var/log/nginx/access.log main;
        # Gzip
        #include global/gzip.conf;
        # Modules
        include /etc/nginx/conf.d/*.conf;
        #upstream reg {
        #  server auth:8080;
        #}
        # Sites
        #include /etc/nginx/sites-enabled/*;
      }
  default: |
    # Define path to cache and memory zone. The memory zone should be unique.
    # keys_zone=fatstcgi-cache:100m creates the memory zone and sets the maximum size in MBs.
    # inactive=60m will remove cached items that haven't been accessed for 60 minutes or more.
    fastcgi_cache_path /cache levels=1:2 keys_zone=fatstcgi-cache:100m inactive=60m;

    server {
      # Ports to listen on, uncomment one.
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
      # Server name to listen for
      server_name reg.cloudnative.zone;
      # Path to document root
      root   /var/www/static;
      # Paths to certificate files.
      ssl_certificate /etc/ssl-dom/fullchain.pem;
      ssl_certificate_key /etc/ssl-dom/privkey.pem;
      # File to be used as index
      index index.php;
      # Overrides logs defined in nginx.conf, allows per site logs.
      error_log /dev/stdout warn;
      access_log /dev/stdout main;
      # Default server block rules
      include server/defaults.conf;
      # Fastcgi cache rules
      include server/fastcgi-cache.conf;
      # SSL rules
      include server/ssl.conf;
      # disable_symlinks off;
      #Used when a load balancer wants to determine if this server is up or not
      location /health_check {
        return 200;
      }
      location / {
          root   /usr/share/nginx/html;
          index  index.html index.htm;
      }
      #location / {
      #  #auth_basic  "Login";
      #  #auth_basic_user_file  /etc/nginx/htpasswd;
      #  proxy_set_header Host $http_host;
      #  proxy_set_header X-Real-IP $remote_addr;
      #  proxy_set_header X-Forwarded-For
      #  $proxy_add_x_forwarded_for;
      #  proxy_redirect off;
      #  proxy_pass reg;
      #}
    }
    # Redirect http to https
    server {
      listen 80;
      listen [::]:80;
      server_name reg.cloudnative.zone;
      #server_name localhost;
      #return 301 https://reg.cloudnative.zone$request_uri;
      #return 301 https://fatstcgi-cache$request_uri;
      location / {
          root   /usr/share/nginx/html;
          index  index.html index.htm;
      }
    }
