user nginx;
pid /run/nginx.pid;
worker_processes 1;
error_log /dev/stderr warn;

events {
	worker_connections 1024;
}

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

	access_log off;
	server_tokens off;
	client_max_body_size 100m;
	sendfile on;

	server {
		listen 8080;
		server_name localhost;

		root /srv/ushahidi;
		index index.php;

		location / {
			try_files $uri /index.html;
		}

		location /platform {
			fastcgi_pass unix:/var/run/ushahidi.sock;
			fastcgi_index index.php;
			include fastcgi_params;
			fastcgi_param SCRIPT_FILENAME $document_root/platform/httpdocs/index.php;
			fastcgi_split_path_info ^(/platform/)(.*)$;
			fastcgi_param PATH_INFO $fastcgi_path_info;
			fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
			fastcgi_param HTTP_HOST $http_x_forwarded_host if_not_empty;
			fastcgi_param HTTPS "on";
			fastcgi_param REQUEST_SCHEME "https";
			fastcgi_param SERVER_NAME $http_x_forwarded_server_name if_not_empty;
			fastcgi_param SERVER_PORT $http_x_forwarded_server_port if_not_empty;
		}

		location /config.json {
			if ($request_method = 'OPTIONS') {
				add_header 'Access-Control-Allow-Origin' '*';
				add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
				add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
				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' '*';
				add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
				add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
				add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
			}
		}
	}
}