apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-conf-file-configmap
data:
  nginx.conf: |
    user  nginx;

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

    worker_processes  auto;
    worker_rlimit_nofile 4096;
    events {
            worker_connections 4096;
            multi_accept on;
    }


    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;
        error_log /var/log/nginx/error.log;

        sendfile        on;
        #tcp_nopush     on;

        keepalive_timeout           600;
        proxy_connect_timeout       600;
        proxy_send_timeout          600;
        send_timeout                600;
        uwsgi_read_timeout          600;

        # This is the main geonode conf
        charset     utf-8;

        # max upload size
        client_max_body_size 100G;
        client_body_buffer_size 256K;
        large_client_header_buffers 4 64k;
        proxy_read_timeout 600s;

        fastcgi_hide_header Set-Cookie;

        etag on;

        # compression
        gzip on;
        gzip_vary on;
        gzip_proxied any;
        gzip_http_version 1.1;
        gzip_disable "MSIE [1-6]\.";
        gzip_buffers 16 8k;
        gzip_min_length 1100;
        gzip_comp_level 6;
        gzip_types
            text/plain
            text/css
            text/js
            text/xml
            text/javascript
            application/javascript
            application/x-javascript
            application/json
            application/xml
            application/rss+xml
            image/svg+xml;

      server{
        listen 80;
        index index.html index.htm;
        root   /mnt/volumes/statics/;

        location /{
            if ($request_method = OPTIONS) {
                add_header Access-Control-Allow-Methods "GET, POST, PUT, PATCH, OPTIONS";
                add_header Access-Control-Allow-Headers "Authorization, Content-Type, Accept";
                add_header Access-Control-Allow-Credentials true;
                add_header Content-Length 0;
                add_header Content-Type text/plain;
                add_header Access-Control-Max-Age 1728000;
                return 200;
            }
            try_files $uri @django;
        }

        location @django {
            include uwsgi_params;
            uwsgi_pass uwsgi://django:8000;

            add_header Access-Control-Allow-Credentials false;
            add_header Access-Control-Allow-Headers "Content-Type, Accept, Authorization, Origin, User-Agent";
            add_header Access-Control-Allow-Methods "GET, POST, PUT, PATCH, OPTIONS";
        }

        location /geoserver {
            proxy_redirect              off;
            proxy_set_header            Host $host;
            proxy_set_header            X-Real-IP $remote_addr;
            proxy_set_header            X-Forwarded-Host $server_name;
            proxy_set_header            X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header            X-Forwarded-Proto $scheme;

            proxy_pass http://geoserver:8080/geoserver;
        }

    }
        #include /etc/nginx/conf.d/*.conf;
    }