|
Nginx默认不支持pathinfo格式的url,最近学习ThinkPHP的URL_MODEL时遇到了这个问题。Apache服务器下开启rewrite,将AllowOverride设置为All就ok了,但是Nginx却需要进一步配置,网上找了很多教程,大都是转载的比较多,试了好几个都没有成功。后来按照另一个教程进行配置,结果ok了。下面是配置过程。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| 1.Nginx.conf下配置如下
server
{
listen 80;
server_name test.com;
index index.php;
root D:/phpStudy/WWW/test;
#这里是开启rewrite隐藏index.php
location / {
if (!-e $request_filename) { # -e表示存在某个文件或目录
rewrite ^(.*)$ /index.php/$1 last; #last相当于apache中的[L],表示不再往下匹配
break;
}
}
#这里是pathinfo的配置
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
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 $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
}
|
2.hosts文件里配置
127.0.0.1 test.com
|
|
|