
upstream upstream_api {
	least_conn;
	server 127.0.0.1:7088;
}

map $http_upgrade $connection_upgrade {
	default upgrade;
	'' close;
}

# HTTP server
#

server {
	listen 7080 default_server;
	server_name unified_api;

	root /usr/share/nginx/html;
	index index.html index.htm;
	autoindex on;
	keepalive_timeout 15;
	
	proxy_set_header   X-Forwarded-Proto	$scheme;
	##proxy_set_header	X-Forwarded-Proto	$http_x_forwarded_proto;
	proxy_set_header   Host               $http_host;
	proxy_set_header   X-Real-IP          $remote_addr;
	proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;
	proxy_set_header   X-Scheme           $scheme;

	#Common API Server
	location / {
		proxy_pass http://upstream_api;
		add_header Cache-Control no-cache;
		proxy_set_header FULL-ADDRESS $scheme://$host:$server_port/;  
		
		if ($request_method = 'OPTIONS') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
													   
			add_header 'Access-Control-Max-Age' 1728000;
			add_header 'Content-Type' 'text/plain; charset=utf-8';
			add_header 'Content-Length' 0;
			return 204;
		}
		if ($request_method = 'GET') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'POST') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'PUT') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'DELETE') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
	}
	
	location /notification {
		proxy_pass http://upstream_api;
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection $connection_upgrade;

		proxy_read_timeout 86400s;
		proxy_send_timeout 86400s;
	}
	
	#IVMS Web Client
	location /ivmsweb {
		proxy_pass http://127.0.0.1:8050/ivmsweb;
		add_header Cache-Control no-cache;
		
		if ($request_method = 'OPTIONS') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
													   
			add_header 'Access-Control-Max-Age' 1728000;
			add_header 'Content-Type' 'text/plain; charset=utf-8';
			add_header 'Content-Length' 0;
			return 204;
		}
		if ($request_method = 'GET') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'POST') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'PUT') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'DELETE') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
	}

	#ITMS Web Dashboard (Speed and RLVD)
	location /itmsweb {
		proxy_pass http://127.0.0.1:8060/itmsweb;
		add_header Cache-Control no-cache;
		
		if ($request_method = 'OPTIONS') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
													   
			add_header 'Access-Control-Max-Age' 1728000;
			add_header 'Content-Type' 'text/plain; charset=utf-8';
			add_header 'Content-Length' 0;
			return 204;
		}
		if ($request_method = 'GET') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'POST') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'PUT') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'DELETE') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
	}

	#TS_FILES
	location /stream {
		alias /usr/share/nginx/html/stream;
		autoindex on;
		autoindex_localtime on;
		add_header Cache-Control no-cache;
		
		if ($request_method = 'OPTIONS') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
													   
			add_header 'Access-Control-Max-Age' 1728000;
			add_header 'Content-Type' 'text/plain; charset=utf-8';
			add_header 'Content-Length' 0;
			return 204;
		}
		if ($request_method = 'GET') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'POST') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'PUT') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'DELETE') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
	}

	#NEW_STREAMING
	location /live {
		proxy_pass http://127.0.0.1:80;
		add_header Cache-Control no-cache;
		
		if ($request_method = 'OPTIONS') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
													   
			add_header 'Access-Control-Max-Age' 1728000;
			add_header 'Content-Type' 'text/plain; charset=utf-8';
			add_header 'Content-Length' 0;
			return 204;
		}
		if ($request_method = 'GET') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'POST') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'PUT') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'DELETE') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
	}
	
	#Events
	location /evidence {
		alias /usr/share/nginx/html/events;
		autoindex on;
		autoindex_localtime on;
		add_header Cache-Control no-cache;
		
		if ($request_method = 'OPTIONS') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
													   
			add_header 'Access-Control-Max-Age' 1728000;
			add_header 'Content-Type' 'text/plain; charset=utf-8';
			add_header 'Content-Length' 0;
			return 204;
		}
		if ($request_method = 'GET') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'POST') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'PUT') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'DELETE') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
	}
}

# HTTPS server
#
server {
	listen       7443 ssl;
	server_name  localhost;

	ssl_certificate      /etc/nginx/ssl/localhost.crt;
	ssl_certificate_key  /etc/nginx/ssl/localhost.key;
	
	ssl_session_cache    shared:SSL:1m;
	ssl_session_timeout  5m;

	ssl_ciphers  HIGH:!aNULL:!MD5;
	ssl_prefer_server_ciphers  on;
	
	root /usr/share/nginx/html;
	index index.html index.htm;
	autoindex on;
	keepalive_timeout 10;

	#Common API Server
	location / {
		proxy_pass http://upstream_api;
		add_header Cache-Control no-cache;
		
		if ($request_method = 'OPTIONS') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
													   
			add_header 'Access-Control-Max-Age' 1728000;
			add_header 'Content-Type' 'text/plain; charset=utf-8';
			add_header 'Content-Length' 0;
			return 204;
		}
		if ($request_method = 'GET') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'POST') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'PUT') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'DELETE') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
	}
	
	location /notification {
		proxy_pass http://upstream_api;
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection $connection_upgrade;

		proxy_read_timeout 86400s;
		proxy_send_timeout 86400s;
	}
	
	#IVMS Web Client
	location /ivmsweb {
		proxy_pass http://127.0.0.1:8050/ivmsweb;
		add_header Cache-Control no-cache;
		
		if ($request_method = 'OPTIONS') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
													   
			add_header 'Access-Control-Max-Age' 1728000;
			add_header 'Content-Type' 'text/plain; charset=utf-8';
			add_header 'Content-Length' 0;
			return 204;
		}
		if ($request_method = 'GET') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'POST') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'PUT') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'DELETE') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
	}

	#ITMS Web Dashboard (Speed and RLVD)
	location /itmsweb {
		proxy_pass http://127.0.0.1:8060/itmsweb;
		add_header Cache-Control no-cache;
		
		if ($request_method = 'OPTIONS') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
													   
			add_header 'Access-Control-Max-Age' 1728000;
			add_header 'Content-Type' 'text/plain; charset=utf-8';
			add_header 'Content-Length' 0;
			return 204;
		}
		if ($request_method = 'GET') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'POST') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'PUT') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'DELETE') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
	}

	#TS_FILES
	location /stream {
		alias /usr/share/nginx/html/stream;
		autoindex on;
		autoindex_localtime on;
		add_header Cache-Control no-cache;
		
		if ($request_method = 'OPTIONS') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
													   
			add_header 'Access-Control-Max-Age' 1728000;
			add_header 'Content-Type' 'text/plain; charset=utf-8';
			add_header 'Content-Length' 0;
			return 204;
		}
		if ($request_method = 'GET') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'POST') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'PUT') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'DELETE') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
	}

	#NEW_STREAMING
	location /live {
		proxy_pass http://127.0.0.1:80;
		add_header Cache-Control no-cache;
		
		if ($request_method = 'OPTIONS') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
													   
			add_header 'Access-Control-Max-Age' 1728000;
			add_header 'Content-Type' 'text/plain; charset=utf-8';
			add_header 'Content-Length' 0;
			return 204;
		}
		if ($request_method = 'GET') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'POST') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'PUT') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'DELETE') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
	}
	
	#Events
	location /evidence {
		alias /usr/share/nginx/html/events;
		autoindex on;
		autoindex_localtime on;
		add_header Cache-Control no-cache;
		
		if ($request_method = 'OPTIONS') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
													   
			add_header 'Access-Control-Max-Age' 1728000;
			add_header 'Content-Type' 'text/plain; charset=utf-8';
			add_header 'Content-Length' 0;
			return 204;
		}
		if ($request_method = 'GET') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'POST') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'PUT') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
		if ($request_method = 'DELETE') {
			add_header 'Access-Control-Allow-Origin' "$http_origin" always;
			add_header 'Access-Control-Allow-Credentials' 'true' always;
			add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
			add_header 'Access-Control-Allow-Headers' 'Accept,Authorization, Keep-Alive,X-CustomHeader,Origin,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
			add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
		}
	}
}
