Nginx 404 document with PHP files

Managed to get it solved with the following server block:

server {
	listen 80 default_server;
	listen [::]:80 default_server ipv6only=on;
	server_name l2ovc.com www.l2ovc.com;
	root /usr/share/nginx/html;
	index index.php;
	error_page 404 /404.php;
	error_page 500 502 503 504 /50x.html;
	location ~ \.php$ {
		try_files $uri /404.php;
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include fastcgi_params;
	}
}