Forum: NGINX HTTP status code bug?

Posted by double (Guest)
on 2010-02-04 21:54
(Received via mailing list)
Hello,

The browser hits a non-existing file. An "error_page" points
to a fastcgi-application. The fastcgi thinks this is not an error
and explicit sets: "Status: 200" or "Status: 302", ...

One would expect that the fastcgi can overwrite the status-code.

E.g.: http://www.domain.name/media/id12345
nginx returns 404, regardless of the fastcgi.


http {
    server {
        listen          80;
        server_name     www.domain.name;
        error_page      404 /index.cgi;
        location / {
            index           index.cgi;
            fastcgi_pass    unix:/var/run/fastcgi/dispatch.sock;
            ....;
        }
        location ^~ /media/ {
            alias /var/www/media/;
        }
    }
}


Thanks
Marcus

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,50668,50668#msg-50668
Posted by Maxim Dounin (Guest)
on 2010-02-04 22:49
(Received via mailing list)
Hello!

On Thu, Feb 04, 2010 at 03:53:21PM -0500, double wrote:

> The browser hits a non-existing file. An "error_page" points
> to a fastcgi-application. The fastcgi thinks this is not an error
> and explicit sets: "Status: 200" or "Status: 302", ...
> 
> One would expect that the fastcgi can overwrite the status-code.

Normally error pages are mapped to static files, and their status
is obviously 200.  It would be a bit strange to return status 200
just because error page was found, right?

If you want to override original error code with one returned by
error page itself, you should use '=' in error_page directive.
See here for more details:

http://wiki.nginx.org/NginxHttpCoreModule#error_page

> E.g.: http://www.domain.name/media/id12345
> nginx returns 404, regardless of the fastcgi.
> 
> 
> http {
>     server {
>         listen          80;
>         server_name     www.domain.name;
>         error_page      404 /index.cgi;

-         error_page      404 /index.cgi;
+         error_page      404 = /index.cgi;

>         location / {
>             index           index.cgi;                   
>             fastcgi_pass    unix:/var/run/fastcgi/dispatch.sock;
>             ....;        
>         }                                                          
>         location ^~ /media/ {                              
>             alias /var/www/media/;            
>         }                                                          
>     }
> }

Maxim Dounin
Posted by double (Guest)
on 2010-02-04 23:10
(Received via mailing list)
Hi Maxim,

Thank you very much for your help!
RTFM
:-)

Marcus

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?2,50668,50691#msg-50691
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.