Today, I had to deploy some code onto an nginx server. I like nginx because while it’s not as easy to use straight out of the box as apache, it’s not too hard to configure and it’s very fast.

I set up my virtual host:

server {
	root /var/www/;

… and I checked the site. Server error?!

Failed opening required '/var/www/

I know I put the trailing slash in the document root, so why is nginx stripping it?

The solution is in /etc/nginx/fastcgi_params. Just change:

fastcgi_param	DOCUMENT_ROOT		$document_root;


fastcgi_param	DOCUMENT_ROOT		$document_root/;

and restart nginx. It feels like a bit of a hack, but you now have the trailing slash you need.