Requests ending with / (slash) are returning 404

Igor Sysoev igor at sysoev.ru
Wed Apr 7 13:20:43 MSD 2010


On Wed, Apr 07, 2010 at 07:10:42PM +1000, Leonardo Crespo wrote:

> Hi Edho, thanks.
> 
> Igor mentioned i should keep this to avoid serving php as static files.
> 
> location ~ \.php$
> 	{
> 		fastcgi_pass 127.0.0.1:9000;
> 		fastcgi_intercept_errors on;
> 		fastcgi_index index.php;
> 		include /usr/local/nginx/conf/fastcgi_params;
> 		fastcgi_param SCRIPT_FILENAME
> /home/public_html/boysdownunder.com.au/public/$fastcgi_script_name;
> 	}
> 
> Will it conflict with this?
> 
> > location ~ \.php$ {
> >  return 404;
> > }
> 
> Since i don't want direct request to .php files anyway, I assume it
> won't but just to be safe.

You should use the later variant.
The former should be used if you want to handle something like "/foo/page.php".

> Cheers
> 
> On Wed, Apr 7, 2010 at 7:04 PM, Edho P Arief <edhoprima at gmail.com> wrote:
> > On Wed, Apr 7, 2010 at 3:58 PM, Leonardo Crespo <leo at leocrespo.com> wrote:
> >> Wow, very elegant Igor. Thank you, it works beautifully.
> >>
> >> Could you help with the last bit?
> >>
> >> I'd like to return 404 if the user tries /foo/page.php instead of /foo/page
> >>
> >
> > location / {
> >  try_files $uri @php;
> > }
> > location @php {
> >  try_files $uri.php $uri/ =404;
> >  fastcgi_pass 127.0.0.1:9000;
> >  fastcgi_intercept_errors on;
> >  fastcgi_index index.php;
> >  include /usr/local/nginx/conf/fastcgi_params;
> >  fastcgi_param SCRIPT_FILENAME
> >    /home/public_html/domain.com.au/public/$fastcgi_script_name;
> > }
> > location ~ \.php$ {
> >  return 404;
> > }
> >
> >
> > --
> > O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
> >
> > _______________________________________________
> > nginx mailing list
> > nginx at nginx.org
> > http://nginx.org/mailman/listinfo/nginx
> >
> 
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx

-- 
Igor Sysoev
http://sysoev.ru/en/



More information about the nginx mailing list