apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app.kubernetes.io/name: home-assistant
  name: home-assistant-nginx-config
  namespace: internet-of-things
data:
  nginx.conf: |-
    user                       nginx;
    worker_processes           1;
    error_log                  /var/log/nginx/error.log warn;
    pid                        /var/run/nginx.pid;
    events {
      worker_connections       2048;
      use                      epoll;
      multi_accept             on;
    }
    http {
      include                  /etc/nginx/mime.types;
      default_type             application/octet-stream;
      log_format               main  '$http_cf_connecting_ip - $http_cf_ipcountry [$time_local] "$request" '
                                     '$status $body_bytes_sent "$http_referer" '
                                     '"$http_user_agent"';
      access_log               /var/log/nginx/access.log  main;
      server_tokens            off;
      sendfile                 on;
      tcp_nopush               on;
      tcp_nodelay              on;
      keepalive_timeout        60 60;
      types_hash_max_size      2048;
      keepalive_requests       1000;
      gzip                     on;
      gzip_comp_level          5;
      gzip_vary                on;
      gzip_disable             "MSIE [1-6]\.(?!.*SV1)";
      gzip_proxied             expired no-cache no-store private auth;
      gzip_min_length          256;
      gzip_types
                               application/atom+xml
                               application/javascript
                               application/json
                               application/rss+xml
                               application/vnd.ms-fontobject
                               application/x-font-ttf
                               application/x-font-opentype
                               application/x-font-truetype
                               application/x-javascript
                               application/x-web-app-manifest+json
                               application/xhtml+xml
                               application/xml
                               font/eot
                               font/opentype
                               font/otf
                               font/truetype
                               image/svg+xml
                               image/x-icon
                               image/vnd.microsoft.icon
                               text/css
                               text/plain
                               text/javascript
                               text/x-component;
      open_file_cache          max=200000 inactive=20s;
      open_file_cache_valid    30s;
      open_file_cache_min_uses 2;
      open_file_cache_errors   on;
      proxy_buffering          off;
      fastcgi_buffers              4 256k;
      fastcgi_busy_buffers_size    256k;
      fastcgi_temp_file_write_size 256k;
      set_real_ip_from             172.16.0.0/12;
      set_real_ip_from             10.0.0.0/8;
      set_real_ip_from             192.168.0.0/16;
      real_ip_header               CF-Connecting-IP;
      server {
        listen 8123 reuseport default_server;
        location /-/status {
          stub_status;
          allow         192.168.0.0/16;
          allow         172.16.0.0/12;
          allow         10.0.0.0/8;
          allow         127.0.0.0/8;
          deny          all;
          access_log    off;
        }
        location / {
          proxy_pass http://127.0.0.1:8124;
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $http_cf_connecting_ip;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
        }
        location /api/websocket {
          proxy_pass http://127.0.01:8124/api/websocket;
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $http_cf_connecting_ip;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
       }
      }
    }
