1

At the moment I'm handling php script using:

location ~ \.php$ {
    fastcgi_pass 127.0.0.1:7777;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

And it's working fine for existing scripts, but when I open http://domain.com/somenotexistingscript.php in my browser, my error log shows:

2013/11/10 21:20:56 [error] 32576#0: *195970 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: x.x.x.x, server: domain.com, request: "GET /somenotexistingscript.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:7777", host: "domain.com"

And the browser shows "File not found". I've tried to add try_files $uri =404 inside given block and open the page again. Default nginx error page appeared but logs showed:

2013/11/10 21:26:55 [error] 1284#0: *18 open() "/www/domain.com127.0.0.1:7777" failed (2: No such file or directory), client: x.x.x.x, server: domain.com, request: "GET /somenotexistingscript.php HTTP/1.1", host: "domain.com"

Using this question I've managed to display custom php error page but unfortunately logs still showing:

2013/11/10 21:20:56 [error] 32576#0: *195970 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: x.x.x.x, server: domain.com, request: "GET /somenotexistingscript.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:7777", host: "domain.com"

Is it possible to handle not existing script and don't log any error information?

0

1 Answer 1

3

Solutions is to use try_files $uri =404; with:

fastcgi_split_path_info ^(.+\.php)(/.+)$;

So the config looks like:

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass 127.0.0.1:7777;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Could you expand on this answer? I'm having the same problem. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.