目前,我正在使用以下方法处理php脚本:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:7777;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}它在现有脚本中运行良好,但当我在浏览器中打开http://domain.com/somenotexistingscript.php时,错误日志显示:
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"浏览器显示“未找到文件”。我尝试在给定的块中添加try_files $uri =404并再次打开页面。出现了默认的nginx错误页面,但是日志显示:
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"使用this question,我成功地显示了自定义php错误页面,但不幸的是,日志仍然显示:
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"是否有可能处理不存在的脚本而不记录任何错误信息?
发布于 2013-11-10 22:16:14
解决方案是在以下情况下使用try_files $uri =404;:
fastcgi_split_path_info ^(.+\.php)(/.+)$;因此,配置如下:
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;
}https://stackoverflow.com/questions/19895717
复制相似问题