第一种,最简单的方法:
加上一句
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/company$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
第二种方法:(注意:nginx 0.5 版此方法无效)
location ~ \.php
{
fastcgi_pass 127.0.0.1:9000;
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 /var/html/$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
include /etc/nginx/fastcgi_params;
}
第一种方法是无效的吧~
[quote=ahu]第一种方法是无效的吧~[/quote]
是有效的,但我是在0.5上面试的,,已通过测试
第一种方法中
location ~ \.php$ {
不对
应该是
location ~ \.php {
$结尾后匹配不了index.php/xx/这样的URL
[quote=fhc]第一种方法中
location ~ \.php$ {
不对
应该是
location ~ \.php {
$结尾后匹配不了index.php/xx/这样的URL[/quote]
没错,,,应该是 location ~ \.php {
因为我每个index.php/abc
都单独写了rewrite,所以没注意到!!
请问,我两种方法都试了,还是不行,而且出现了Restarting nginx: nginx: [warn] conflicting server name “localhost” on 0.0.0.0:80, ignored
这是为什么啊?
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
location ~ .*\.php(.*)$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
上面是最新的方法,nginx 1.0+可用