apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-config
data:
  nginx.conf: |
    user              nginx;
    worker_processes  5;

    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;

    events {
        worker_connections  4096;
    }

    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;
        gzip                on;
        keepalive_timeout   30;

        include /etc/nginx/conf.d/*.conf;
    }
  default.conf: |
    server {
        listen      80 default_server;
        listen [::]:80 default_server;

        # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
        return 301 https://$host$request_uri;
    }

    server {
        listen      443 ssl http2;
        listen [::]:443 ssl http2;

        server_name             localhost;
        ssl_certificate         /etc/nginx/ssl/nginx.crt;
        ssl_certificate_key     /etc/nginx/ssl/nginx.key;

        location /api/chat/ {   # proxy '/chat' requests to chamise
            proxy_set_header  Host $host;
            proxy_set_header  X-Real-IP $remote_addr;
            proxy_pass        http://10.0.0.170:80/;
        }

        location /api/accounts/ {
            proxy_set_header  Host $host;
            proxy_set_header  X-Real-IP $remote_addr;
            proxy_pass        http://10.0.0.200:80/;
        }

        location /socket/ {     # websocket
            proxy_pass          http://10.0.0.170:8000/;
            proxy_http_version  1.1;
            proxy_set_header    Upgrade $http_upgrade;
            proxy_set_header    Connection "upgrade";
            proxy_set_header    Host $host;
            proxy_read_timeout  3600;
        }

        location / {            # everything else to naamio
            proxy_set_header  Host $host;
            proxy_set_header  X-Real-IP $remote_addr;
            proxy_pass        http://10.0.0.180:80;
        }
    }
