404 instead of "no inout file specified"?

Maxim Dounin mdounin at mdounin.ru
Tue Jul 7 23:38:52 MSD 2009


Hello!

On Wed, Jul 08, 2009 at 01:47:34AM +0800, Leechael Yim wrote:

> <code lang="nginx">
> if (-f $request_filename) {    fastcgi_pass 127.0.0.1:9000;
> }
> </code>
> 
> OR:
> 
> <code lang="nginx">
> if (!-f $request_filename) {
>     return 404;
> }
> fastcgi_pass 127.0.0.1:9000;
> </code>
> 
> The first one is what I current used with my Nginx.

Both snippets

1. Use if() which is evil.  It was explained a lot of times here 
why if's are evil, so I'm not going to repeat.

2. Just won't work with backend(s) on other host(s).

Maxim Dounin

> 
> On Wed, Jul 1, 2009 at 10:20 PM, Maxim Dounin <mdounin at mdounin.ru> wrote:
> 
> > Hello!
> >
> > On Wed, Jul 01, 2009 at 02:52:06PM +0100, Nuno Magalhães wrote:
> >
> > > Greetings,
> > >
> > > If i provide a valid URL, it's processed.
> > > If i provide an invalid URL, nginx shows the 404 page except it the
> > > invalid URL ends in .php - in that case i get the "no input file
> > > specified" message.
> >
> > Looks like you've configured passing urls ending with ".php" to
> > php for processing.  So you got errors from php, not from nginx.
> > It's expected behaviour, no?
> >
> > And, actually, "no input file specified" *is* 404 error.  It's
> > just has some fancy php-specific content.
> >
> > > I'm in the process of changing my php files to an html extension (i
> > > assume that would "fix" things), however, i'd like to get a 404
> > > instead of the message regardless.
> > >
> > > I tried using "fastcgi_intercept_errors off" in the conf for my server
> > > (in sites-available), but it didn't do anything (i did restart both
> > > nginx and the fast-cgi processes).
> > >
> > > Is there a better way?
> >
> > If you want to change error page returned by php to something
> > pretty-looking, you should:
> >
> > 1. Use "fastcgi_intercept_errors on;" to instruct nginx to
> > intercept and change errors returned by fastcgi application.
> >
> > 2. Make sure you explicitly configured error_page for 404.
> > Default compiled-in error pages are used only for nginx own
> > errors, not for fastcgi_intercept_errors/proxy_intercept_errors.
> >
> > So your resulting config should look like:
> >
> >    error_page  404  /404.html;
> >
> >    location ~ \.php$ {
> >        fastcgi_pass ...;
> >        fastcgi_intercept_errors on;
> >    }
> >
> >    ...
> >
> > Maxim Dounin
> >
> >
> 
> 
> -- 
> Twitter: http://www.twitter.com/leechael





More information about the nginx mailing list