原文:
https://blog.csdn.net/qqwtohot/article/details/52130933
按照yaf手册上面的nginx rewrite配置完成后,如果是用的nginx+php-fpm模式,一般情况下是解析不了的,不是404就是Access denied的提示,要不就是访问其他的页面的时候,地址是对的,返回结果却是主页(index)的。
今天配置的时候就出了这个问题,查了大部分资料都是说把
location / {
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php/$1 last;
}
}
改成
location / {
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php?$1 last;
}
}
我觉得这样不太科学啊,既然是path_info这上面的问题,那估计就得在nginx配置上找原因了。
通过对正则的调整,还有转发的规则调整,总算是搞定了。
fastcgi_params配置得足够,各种该带的一个也不能少,尤其是path_info这块的。
下面是 server 的配置
server {
listen 80;
server_name nk.yaf.com;
root /Users/xingkaroc/mywww/yaf;
index index.html index.php;
access_log logs/nkyafcom.access.log main;
error_log logs/nkyafcom.error.log info;
#if (-f $request_filename) {
# break;
#}
location / {
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location ~* .php {
fastcgi_split_path_info ^(.+?.php)(/.*)$;
fastcgi_param HTTP_PROXY "";
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
fastcgi_params的配置
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
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;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS
最后就是,PHP里面,php.ini需要开启 cgi.fix_pathinfo 这个参数
cgi.fix_pathinfo=1
按照这样配置,yaf就能正常使用了。
---------------------
作者:石角
来源:CSDN
原文:https://blog.csdn.net/qqwtohot/article/details/52130933
版权声明:本文为博主原创文章,转载请附上博文链接!