#Config MAp to store ngninx.conf 
# kubectl apply -f nginx-config.yml
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-conf-detail
data:
  nginx.conf: |-
    user  nginx;
    worker_processes  1;

    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;
    #load_module modules/ngx_http_modsecurity_module.so;

    events {
        worker_connections  1024;
    }

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

        sendfile        on;
        keepalive_timeout  65;

        log_format elk_format 'time=[$time_local] proxy_host=$proxy_host client_ip=$remote_addr virtual=$server_name client_port=$remote_port xff_ip=$http_X_Forwarded_For lb_server=$upstream_addr http_host=$host http_method=$request_method http_request_uri=$request_uri status_code=$status content_type=$sent_http_content_type content_length=$sent_http_content_length response_time=$request_time referer="$http_referer" http_user_agent="$http_user_agent" x-request-id=$http_x_request_id ';
        
        upstream detail {
            server 127.0.0.1:9080;
        }

        server {
            listen 8443 ssl;
            underscores_in_headers on;
            server_name detail-https;

            access_log syslog:server=10.69.33.1:8516 elk_format;	
            
            #modsecurity on;
            #modsecurity_rules_file /etc/nginx/modsec/main.conf;

            ssl_certificate      /app/cert/ssl-cert;
            ssl_certificate_key  /app/cert/ssl-key;
            #ssl_client_certificate /app/cert/ca-cert;
            #ssl_verify_client on;

            ssl_protocols TLSv1.2;
            ssl_ciphers EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:!EECDH+3DES:!RSA+3DES:!MD5;
            ssl_prefer_server_ciphers on;

            location / {
                proxy_pass         http://detail;
                proxy_redirect     off;
            }
        }

        server {
            listen 8080;
            server_name detail-http;
            underscores_in_headers on;

            #access_log syslog:server=10.69.33.1:8516 elk_format;
            access_log /var/tmp/nginx-access.log elk_format;

            #modsecurity on;
            #modsecurity_rules_file /etc/nginx/modsec/main.conf;

            location / {
                #proxy_set_header proxy_host detail;
                proxy_pass         http://detail;
                proxy_redirect     off;
            }
        }

        server {
            listen 8081 default_server;
            #underscores_in_headers on;

            location / {
                resolver 10.128.0.1 10.129.0.1 10.130.0.1 valid=10s;
                proxy_buffering    off;
                proxy_pass         https://$http_host:8443;

                proxy_ssl_certificate    /app/cert/adc-cert;
                proxy_ssl_certificate_key   /app/cert/adc-key;
            }
        }
    }
