打开 nginx 的配置文件 nginx.conf 文件,修改如下:
01 # 我使用的是虚拟主机配置
02 server {
03 listen 80;
04 server_name dev.example.com;
05
06 rewrite_log on;
07
08 root /www/web/htdocs/dev.example.com;
09 index index.php index.html index.htm;
10
11 location / {
12 index index.php index.html index.htm;
13 }
14
15 location ~ \.php($|/) {
16 fastcgi_pass 127.0.0.1:9000;
17 fastcgi_index index.php;
18 fastcgi_split_path_info ^(.+\.php)(.*)$; //注1
19 fastcgi_param PATH_INFO $fastcgi_path_info;
20 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
21 include fastcgi_params;
22 }
23
24 if (!-e $request_filename) {
25 rewrite ^/(.*)$ /index.php/$1 last;
26 break;
27 }
28
29 location ~ /\.ht {
30 deny all;
31 }
32 }
注1
****PATH_INFO:
该指令的参数是一个正则表达式分组一标识 $fastcgi_script_name、分组二标识 $fastcgi_path_info(等同于PHP $_SERVER 中的 PATH_INFO),前提条件是nginx版本大于0.7.31。
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $path_info;
官方示例:
location ~ ^.+\.php {
...
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
...
}

浙公网安备 33010602011771号