Forum: NGINX FastCGI returning "No Input File" instead of 404

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0de2f671d213ed51e615890465ea6097?d=identicon&s=25 APseudoUtopia (Guest)
on 2009-05-21 18:31
(Received via mailing list)
Hey everyone,

This seems like it would be easily solved, but I'm not sure how. I
just finished setting up PHP on my system. It runs fine. However, when
I browse to a page like
"http://domain.com/this-php-script-does-not-exist.php" it returns "No
input file specified" instead of a normal nginx 404 error. I'm trying
to get it to display a normal 404 error instead. I've tried toggling
the fastcgi_intercept_errors, which seems like it would fix the
problem, however it didn't work.

I'm running nginx stable, 0.6.37.

It seems that try_files would work somehow, but my understanding is
that try_files does not exist in 0.6.37?

My FastCGI config is below.

location ~ .*\.php$ {
  fastcgi_index index.php;
  fastcgi_ignore_client_abort off;
  fastcgi_intercept_errors off;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_read_timeout 10; # sec to wait for php-cgi to return data
  fastcgi_param SCRIPT_FILENAME
/usr/local/www/web_root$fastcgi_script_name;
  include /usr/local/etc/nginx/fastcgi_params;
}

Thank you for any and all help.
F5a6ed477b109fe6acc11a5a8f87e7e8?d=identicon&s=25 Michael Shadle (Guest)
on 2009-05-21 18:38
(Received via mailing list)
i was going to say this is the typical "check your SCRIPT_FILENAME"
but you already know that.

this is an interesting question. Igor would it be possible to
intercept this (or with a combination from php-fpm/the SAPI) to detect
these errors and present the 404 (or appropriate) handler defined?
either nginx default 404 or in the case of error_page being set using
that one (like a normal file-does-not-exist.html)

[root@web01 ~]# lynx -mime_header http://foo.com/script-doesnt-exist.php
HTTP/1.0 404 Not Found
Server: nginx
Content-Type: text/html; charset=utf-8
Vary: Accept-Encoding
Content-Encoding: gzip
Date: Thu, 21 May 2009 16:32:12 GMT
Content-Length: 45
Connection: close

it appears to throw a 404, but for some reason isn't the normal nginx
404?
96dfd0f0a8399d3b03feba1e6a562e0a?d=identicon&s=25 Edho P Arief (Guest)
on 2009-05-21 18:48
(Received via mailing list)
On Thu, May 21, 2009 at 11:25 PM, APseudoUtopia
<apseudoutopia@gmail.com> wrote:
>
> I'm running nginx stable, 0.6.37.
>
> It seems that try_files would work somehow, but my understanding is
> that try_files does not exist in 0.6.37?
>
> My FastCGI config is below.
>
> location ~ .*\.php$ {
if (!-f $request_filename) { return 404; break; }
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-05-21 19:55
(Received via mailing list)
On Thu, May 21, 2009 at 11:41:45PM +0700, Edho P Arief wrote:

> > problem, however it didn't work.
> >
> > I'm running nginx stable, 0.6.37.
> >
> > It seems that try_files would work somehow, but my understanding is
> > that try_files does not exist in 0.6.37?
> >
> > My FastCGI config is below.
> >
> > location ~ .*\.php$ {
> if (!-f $request_filename) { return 404; break; }

NO! NO! NO!
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-05-21 19:55
(Received via mailing list)
On Thu, May 21, 2009 at 12:25:09PM -0400, APseudoUtopia wrote:

>
>   fastcgi_intercept_errors off;
-   fastcgi_intercept_errors off;
+   fastcgi_intercept_errors on;
+  error_page  404  /404.html;

>   fastcgi_pass 127.0.0.1:9000;
>   fastcgi_read_timeout 10; # sec to wait for php-cgi to return data
>   fastcgi_param SCRIPT_FILENAME /usr/local/www/web_root$fastcgi_script_name;
>   include /usr/local/etc/nginx/fastcgi_params;
> }

  location = /404.html {
     root /path/to/the/page;
  }
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-05-21 20:05
(Received via mailing list)
On Thu, May 21, 2009 at 12:25:09PM -0400, APseudoUtopia wrote:

>
> I'm running nginx stable, 0.6.37.
>
> It seems that try_files would work somehow, but my understanding is
> that try_files does not exist in 0.6.37?

try_files exists in 0.6.36+.
You may try this also:

 location ~ .*\.php$ {
  try_files  $uri  /404.html;

  fastcgi_pass 127.0.0.1:9000;
  ...
96dfd0f0a8399d3b03feba1e6a562e0a?d=identicon&s=25 Edho P Arief (Guest)
on 2009-05-22 03:31
(Received via mailing list)
2009/5/22 Igor Sysoev <is@rambler-co.ru>:
>> the fastcgi_intercept_errors, which seems like it would fix the
>  location ~ .*\.php$ {
>        try_files  $uri  /404.html;
>
>        fastcgi_pass 127.0.0.1:9000;
>        ...
>

thanks. is there a way to return default 404?

Or is this the correct way?

location ~ \.php${
try_files  $uri @404;
...
}
...
location @404 { return 404; break; }
0de2f671d213ed51e615890465ea6097?d=identicon&s=25 APseudoUtopia (Guest)
on 2009-05-22 08:02
(Received via mailing list)
2009/5/21 Igor Sysoev <is@rambler-co.ru>:
>> the fastcgi_intercept_errors, which seems like it would fix the
>  location ~ .*\.php$ {
>>       fastcgi_intercept_errors off;
> Igor Sysoev
> http://sysoev.ru/en/
>
>

Thanks a lot! Got it working perfectly. I appreciate the time and work
you put into the project. Thanks again!
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-05-22 09:34
(Received via mailing list)
On Fri, May 22, 2009 at 08:23:36AM +0700, Edho P Arief wrote:

> >> to get it to display a normal 404 error instead. I've tried toggling
> >
> > šlocation ~ .*\.php$ {
> > š š š štry_files š$uri š/404.html;
> >
> > š š š šfastcgi_pass 127.0.0.1:9000;
> > š š š š...
> >
>
> thanks. is there a way to return default 404?

Why do you want to return default 404 at all ? The default error
pages are last resort and should be customized on a good site.

> Or is this the correct way?

You may use "if" or example below:

> location ~ \.php${
> try_files  $uri @404;
> ...
> }
> ...
> location @404 { return 404; break; }

You do not need "break" after "return", because "return" breaks
execution
by itself.
96dfd0f0a8399d3b03feba1e6a562e0a?d=identicon&s=25 Edho P Arief (Guest)
on 2009-05-22 11:39
(Received via mailing list)
2009/5/22 Igor Sysoev <is@rambler-co.ru>:
>> >> "http://domain.com/this-php-script-does-not-exist.php" it returns "No
>> > try_files exists in 0.6.36+.
>
>> }
>> ...
>> location @404 { return 404; break; }
>
> You do not need "break" after "return", because "return" breaks execution
> by itself.
>

I suspected it isn't needed.
The reason would be to use whatever error_page that's located in
server block so I only need to specify it once. (it works, right?)
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-05-22 12:24
(Received via mailing list)
On Fri, May 22, 2009 at 04:31:08PM +0700, Edho P Arief wrote:

> >> >> I browse to a page like
> >> >
> >> thanks. is there a way to return default 404?
> >> ...
> server block so I only need to specify it once. (it works, right?)
server {
    error_page  404 = /404.html;

    location = /404.html {
    }

    location ~ \.php${
        try_files $uri /404.html;

        fastcgi_pass  ...
    }
This topic is locked and can not be replied to.