nginx-php fastcgi配置,php文件404错误问题。

mia0x75 发布于 2015/06/08 08:27
阅读 2K+
收藏 0
server {
    listen              80;
    server_name
                        www.domain.cn
                        ;
    charset             utf-8;
    set                 $root '/dat/www/www.domain.cn/public';
    root                $root;

    index               index.php index.html index.htm;
    try_files           $uri $uri/ @rewrite;
    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;
    }

    location ~ \.php$ {
        root           $root;
        try_files      $uri = 404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}


访问不存在的php就会出现这个错误。

2015/06/08 06:29:06 [error] 24104#0: *37125 open() "/dat/www/www.domain.cn/public404" failed (2: No such file or directory), client: 123.125.71.58, server: www.domain.cn, request: "GET /news.php HTTP/1.1", host: "www.domain.cn"

即便增加fastcgi_intercept_errors on,也还是会有此类的错误信息在error.log中。

加载中
0
eechen
eechen
注意 try_files $uri =404; 这一句
=404 之间是没有空格的.

http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page
自定义404页面,比如交给PHP处理:
error_page 404 = /404.php;
访问不存在的PHP文件时返回404:
location ~ \.php$ { try_files $uri =404; }
0
jk409
jk409
你把错误日志注释掉,看看
0
huangyanxiong
huangyanxiong


set                 $root '/dat/www/www.domain.cn/public';
root                $root;

上面写了,就不要在这里也写了

location ~ \.php$ {
        root           $root;
        try_files      $uri = 404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;



另外确定你文件是否真的存在



返回顶部
顶部