user nginx;
pid /var/run/nginx.pid;

worker_processes 1;

events {
        worker_connections 1024;
    }

http {

    ##
	# Basic Settings
	##

	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 65;
	types_hash_max_size 8192;

    # Hide nginx version information.
    server_tokens off;
    
    server_name_in_redirect off;

    # Specify MIME types for files.
    include /etc/nginx/mime.types;
	default_type application/octet-stream;

    #upstream elasticsearch {
    #    server elasticsearch-1:9200;
    #}

    #upstream kibana {
    #    server kibana:5601;
    #}

    upstream nifi {
        server nifi:8443;
    }

    #server {
    #    listen 9200;
    #    server_name elasticsearch.local;

    #    location / {
    #        proxy_pass http://elasticsearch;
    #        
    #        proxy_set_header X-ProxyScheme http;
    #        proxy_set_header X-ProxyHost nginx.docker.localhost;
    #        proxy_set_header X-ProxyPort 9200;
    #        proxy_set_header X-ProxyContextPath /;
    #    }
    #}

    #server {
    #    listen 5601;
    #    server_name kibana.local;

    #    location / {
    #        proxy_pass http://kibana;
    #        
    #        proxy_set_header X-ProxyScheme http;
    #        proxy_set_header X-ProxyHost nginx.docker.localhost;
    #        proxy_set_header X-ProxyPort 5601;
    #        proxy_set_header X-ProxyContextPath /;
    #    }
    #}

    #server {
    #    listen 80;
    #    listen [::]:80;
    #    server_name nginx.local; 
    #    return 301 https://$host$request_uri;
    #}


    server {
        listen 8443 ssl;
        server_name nginx.local;
        ssl_certificate /etc/nginx/root-ca.pem;
        ssl_certificate_key /etc/nginx/root-ca.key;

        # if you comment this out then you will automatically enable authentication, because nginx won't certify your session...
        # proxy_ssl_certificate /etc/nginx/nifi-cert.pem;
        # proxy_ssl_certificate_key /etc/nginx/nifi-key.key;

        proxy_ssl_trusted_certificate /etc/nginx/nifi-cert.pem;
        proxy_ssl_server_name on;

        location / {
            proxy_set_header Host nifi;
            proxy_set_header X-Real-IP nifi;
            proxy_set_header X-ProxyHost nifi;
            proxy_set_header X-ProxyPort 8443;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-ProxyScheme $scheme;
            # proxy_set_header X-ProxyContextPath /;
            # proxy_set_header X-Forwarded-Context /;
            proxy_pass https://nifi;
        }

        location /nifi {
            proxy_set_header Host nifi;
            proxy_set_header X-Real-IP nifi;
            proxy_set_header X-ProxyHost nifi;
            proxy_set_header X-ProxyPort 8443;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-ProxyScheme $scheme;
        #   proxy_set_header X-Forwarded-Context /nifi;
        #   proxy_set_header X-ProxyContextPath /nifi;
            proxy_pass https://nifi;
        }

        location ^~ /nifi-api/ {
            proxy_set_header Host nifi;
            proxy_set_header X-Real-IP nifi;
            proxy_set_header X-ProxyHost $host;
            proxy_set_header X-ProxyPort 8443;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-ProxyScheme $scheme;
            proxy_hide_header X-Frame-Options;
            proxy_pass https://nifi/nifi-api/;
        }

        # location ^~ /nifi-api/flowfile-queues/ {
        #     proxy_set_header Host nifi;
        #     proxy_set_header X-Real-IP nifi;
        #     proxy_set_header X-ProxyHost $host;
        #     proxy_set_header X-ProxyPort 8443;
        #     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        #     proxy_set_header X-ProxyScheme $scheme;
        #     proxy_hide_header Content-Security-Policy;
        #     add_header Content-Security-Policy "";
        #     proxy_pass https://nifi/nifi-api/flowfile-queues/;
        # }

        location ^~ /media/ {
            proxy_set_header Host nifi;
            proxy_set_header X-Real-IP nifi;
            proxy_set_header X-ProxyHost $host;
            proxy_set_header X-ProxyPort 8443;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-ProxyScheme $scheme;
            proxy_pass https://nifi/media/;
        }

        location ^~ /content-viewer/ {
            proxy_set_header Host nifi;
            proxy_set_header X-Real-IP nifi;
            proxy_set_header X-ProxyHost $host;
            proxy_set_header X-ProxyPort 8443;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-ProxyScheme $scheme;
            proxy_pass https://nifi/content-viewer/;
        }

      #  location ~ ^(/nifi-standard-content-viewer-[0-9.]+/.*)$ {
      #      proxy_set_header Host nifi;
      #      proxy_set_header X-Real-IP $remote_addr;
      #      proxy_set_header X-ProxyHost $host;
      #      proxy_set_header X-ProxyPort 8443;
      #      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      #      proxy_set_header X-ProxyScheme $scheme;

      #      add_header Access-Control-Allow-Origin $http_origin always;
      #      add_header Access-Control-Allow-Credentials true;
      #      add_header Access-Control-Allow-Headers *;

      #      # Relax CSP if needed
      #      proxy_hide_header Content-Security-Policy;
      #      add_header Content-Security-Policy "";

      #      proxy_pass https://nifi$1;
      #  }

       location ^~ /nifi-standard-content-viewer-2.4.0/ {
          proxy_set_header Host nifi;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-ProxyHost $host;
          proxy_set_header X-ProxyPort 8443;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-ProxyScheme $scheme;
          proxy_pass https://nifi/nifi-standard-content-viewer-2.4.0/;
       }    

        location ^~ /nifi-registry-api/ {
            proxy_set_header Host nifi;
            proxy_set_header X-Real-IP nifi;
            proxy_set_header X-ProxyHost $host;
            proxy_set_header X-ProxyPort 8443;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-ProxyScheme $scheme;
            proxy_pass https://nifi/nifi-registry-api/;
        }
    }
}
