nginx重写模块无法正常工作?

时间:2013-07-15 20:05:51

标签: nginx

我有nginx.conf到fuelphp

location / {
    if (!-e $request_filename) {
        rewrite ^(.*)$ index.php?/$1 last;
    }
}

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index  index.php;
    include        fastcgi.conf;
    include /etc/nginx/fastcgi_params;
}

但这不适用于testfphp / public / welcome / hello

nginx说:找不到文件

谢谢。

1 个答案:

答案 0 :(得分:0)

您似乎在不理解它们的情况下混合了不同操作方法的不同位。观察:

rewrite ^(.*)$ index.php?/$1 last; #question mark, typo?
location ~ \.php$ # matches end of request_uri
fastcgi_split_path_info ^(.+\.php)(/.+)$; # matches .php followed by a slash

对于要匹配的第三个语句,.php永远不会在request_uri的末尾,因此此语句永远不会在此位置匹配。

从第一个语句中删除问号,从该位置删除美元符号。然后添加:

fastcgi_param SCRIPT_FILENAME $document_root$ fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_split_pathinfo;

到位置块。尝试从文档中了解并尝试进一步限制位置块。

相关问题