Trailing slash being removed from document root

Francis Daly francis at daoine.org
Wed Jan 4 22:56:58 UTC 2012


On Wed, Jan 04, 2012 at 05:30:42PM -0500, freejack wrote:

Hi there,

> When getting the document root in PHP from nginx using this:
> 
> $_SERVER['DOCUMENT_ROOT']."../".$ZONE."/".$LOCALE...etc......
> 
> nginx will always return the path WITHOUT the trailing slash.

nginx doesn't do PHP, it does fastcgi. Which means that it sends a series
of key/value params to the fastcgi server, which in turn presents them
to your PHP in the _SERVER array.

Which in turn means that...

> We have way too much code in php that gets the document root without
> adding a trailing slash after $_SERVER['DOCUMENT_ROOT'] because lighttpd
> and apache before that always had preserved the trailing slash.
> 
> How can I configure nginx to keep the slash?

...wherever you currently set "fastcgi_param DOCUMENT_ROOT" (probably from
"include fastcgi.conf"), add the slash there and it all should Just Work.

That is:

you probably have

  fastcgi_param DOCUMENT_ROOT $document_root;

Change it to be

  fastcgi_param DOCUMENT_ROOT $document_root/;

and on nginx -s reload, you should see the difference.

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list