apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-base.config
  namespace: demo
data:
  nginx.conf: |-
    # Nginx.conf for Skuid.
    # Only ever mount this in /opt/nginx
    #user www-data;
    worker_processes 2;
    pid /var/run/nginx.pid;
    daemon off;

    events {
        worker_connections 1024;
    }

    http {
        # Basic Settings
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        server_tokens off;

        default_type text/html;

        set_real_ip_from  192.168.0.0/16;
        set_real_ip_from  172.16.0.0/12;
        real_ip_header    X-Forwarded-For;
        real_ip_recursive on;

        # Logging Settings
        log_format main '$http_x_forwarded_for - '
            '$remote_user '
            '[$time_iso8601] '
            '"$request" '
            '$status '
            '$body_bytes_sent '
            '"$http_referer" '
            '"$http_user_agent" '
            '"$remote_addr"';

        # yes the uri/path naming is confusing, just go with it
        log_format json_log '{'
            '"timestamp": "$time_iso8601", '
            '"remote_addr": "$http_x_forwarded_for", '
            '"proxy_remote_addr": "$remote_addr", '
            '"host": "$host", '
            '"status": $status, '
            '"method": "$request_method", '
            '"uri": "$request_uri", '
            '"path": "$uri", '
            '"body_bytes_sent": $body_bytes_sent, '
            '"http_referer": "$http_referer", '
            '"user_agent": "$http_user_agent", '
            '"request_time": $request_time'
            '}';

        access_log /dev/stdout json_log;
        error_log /dev/stdout;

        # Virtual Host Configs
        include /etc/nginx/sites-enabled/*;
    }
