本文主要是针对服务器是nginx,框架为zend framework时进行配置mvc,将所有请求统一到一个文件处理时的情景
我以一个service为例
server {
listen 80;
server_name www.test.com test.com ;
location / {
root E:/www/www/www.test.com/html;
index index.php index.html index.htm;
if ( !-f $request_filename ) {
rewrite ^(.*)$ /index.php?$1 last;
}
}
location ~* ^.+\.(js|ico|gif|jpg|jpeg|pdf|png|css)$ {
#access_log off;
#日志关闭
expires 7d;
#缓存7天
}
location ~ \.php$ {
root E:/www/www/www.test.com/html;
fastcgi_pass 127.0.0.1:9009;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include fastcgi_params;
}
}
主要修改的地方是黄色,红色,蓝色部分
其中黄色部分主要是将不存在的文件统一到index.php文件处理
红色部分主要是针对静态的css js等文件的处理,其实就是静态文件不做任何处理
最后是蓝色部分,它的作用主要是让存在的文件也转到index.php处理