root E:/HTML;
location / {
index index.php index.html index.htm;
if (!-f $uri){
set $rule_0 1$rule_0;
}
if (!-d $uri){
set $rule_0 2$rule_0;
}
#注意顺序,21与12,结果可不一样
if ($rule_0 = "21"){
#Nginx没有虚拟目录的概念,所以绕开这个问题,加第一组正则匹配。
rewrite ^/([a-z-A-Z]+)/([a-z-A-Z]+)/([a-z-A-Z]+)/?(.*)$ /$1/index.php?controller=$2&action=$3&$4;
rewrite ^/([a-z-A-Z]+)/([a-z-A-Z]+)/?$ /$1/index.php?controller=$2 last;
#这样搞,就可支持X.X.X.X/any_app/controller/action
#在你的应用程序config的环境文件里,dispatcher_url_mode为rewrite,
#当再使用url("some_controller/some_action"),完美了!
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
#一些JS、图片、CSS等静态文件,就不要rewrite了,要不然不正常。开发模式下,把超期设置注释掉。
location ~* ^.+\.(js|ico|gif|jpg|jpeg|pdf|png|css)$ {
access_log off;
expires 7d;
}
location ~ \.php?$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME E:/HTML$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}