worker_processes 4;
pid /var/run/nginx.pid;

events {
	worker_connections 768;
	# multi_accept on;
}

http {
	# Basic Settings
	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 65;
	types_hash_max_size 2048;
	# server_names_hash_bucket_size 64;
	server_tokens off;
	server_name_in_redirect off;

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

	# Logging
	access_log off;
	error_log stderr;

	# Prevent nginx from adding compression; this interacts badly with Sandstorm
	# WebSession due to https://github.com/sandstorm-io/sandstorm/issues/289
	gzip off;

	# Trust the sandstorm-http-bridge's X-Forwarded-Proto.
	map $http_x_forwarded_proto $fe_https {
		default "";
		https on;
	}

	server {
		listen 8000 default_server;
		listen [::]:8000 default_server ipv6only=on;

		# Allow arbitrarily large bodies - Sandstorm can handle them, and requests
		# are authenticated already, so there's no reason for apps to add additional
		# limits by default.
		client_max_body_size 0;

		server_name localhost;
		root /opt/app/public;
		location / {
			index index.php;
			try_files $uri $uri/ /index.php?$query_string;
			autoindex on;
        	sendfile off;
		}
		location ~ \.php$ {
			try_files $uri =404;
            fastcgi_pass unix:/var/run/php7.0-fpm.sock;
            fastcgi_index index.php;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
			fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;


			fastcgi_param  QUERY_STRING       $query_string;
			fastcgi_param  REQUEST_METHOD     $request_method;
			fastcgi_param  CONTENT_TYPE       $content_type;
			fastcgi_param  CONTENT_LENGTH     $content_length;
			
			fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
			fastcgi_param  REQUEST_URI        $request_uri;
			fastcgi_param  DOCUMENT_URI       $document_uri;
			fastcgi_param  DOCUMENT_ROOT      $document_root;
			fastcgi_param  SERVER_PROTOCOL    $server_protocol;
			fastcgi_param  HTTPS              $fe_https if_not_empty;
			
			fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
			fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
			
			fastcgi_param  REMOTE_ADDR        $remote_addr;
			fastcgi_param  REMOTE_PORT        $remote_port;
			fastcgi_param  SERVER_ADDR        $server_addr;
			fastcgi_param  SERVER_PORT        $server_port;
			fastcgi_param  SERVER_NAME        $server_name;
			
			# PHP only, required if PHP was built with --enable-force-cgi-redirect
			#fastcgi_param  REDIRECT_STATUS    200;
		}
	}
}
