开发的人跟我说基于thinkphp框架开发的代码在apache下能用,在nginx下为什么用不了呢,总是提示404的错误,原来apache默认就支持thinkphp等所需的PATH_INFO,而nginx不可以,那么接下来,我们就配置一下nginx,让他支持PATH_INFO,我是这么做的:
1,更改php.ini
首先php.ini的配置中把
;cgi.fix_pathinfo=0 改为
cgi.fix_pathinfo=1
2,改nginx配置文件中php的location如下:
location ~ \.php {
fastcgi_pass unix:/dev/shm/php-fcgi.sock;
fastcgi_index index.php;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME /data/www/wwwroot$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
include /usr/local/nginx/conf/fastcgi_params;
}
以前是这样的:
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www/wwwroot$fastcgi_script_name;
1,更改php.ini
首先php.ini的配置中把
;cgi.fix_pathinfo=0 改为
cgi.fix_pathinfo=1
2,改nginx配置文件中php的location如下:
location ~ \.php {
fastcgi_pass unix:/dev/shm/php-fcgi.sock;
fastcgi_index index.php;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME /data/www/wwwroot$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
include /usr/local/nginx/conf/fastcgi_params;
}
以前是这样的:
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www/wwwroot$fastcgi_script_name;
编辑回复