nginx支持yaf的path_info配置

原文:php

https://blog.csdn.net/qqwtohot/article/details/52130933html

 

按照yaf手冊上面的nginx rewrite配置完成後,若是是用的nginx+php-fpm模式,通常狀況下是解析不了的,不是404就是Access denied的提示,要不就是訪問其餘的頁面的時候,地址是對的,返回結果倒是主頁(index)的。nginx

今天配置的時候就出了這個問題,查了大部分資料都是說把php-fpm

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

改爲.net

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

我以爲這樣不太科學啊,既然是path_info這上面的問題,那估計就得在nginx配置上找緣由了。htm

經過對正則的調整,還有轉發的規則調整,總算是搞定了。blog

fastcgi_params配置得足夠,各類該帶的一個也不能少,尤爲是path_info這塊的。ip

下面是 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

相關文章
相關標籤/搜索