《nginx要怎么配置rewrite才能運行vephp、yii和thinkphp等MVC框架?》要點:
本文介紹了nginx要怎么配置rewrite才能運行vephp、yii和thinkphp等MVC框架?,希望對您有用。如果有疑問,可以聯系我們。
相關主題:YII框架
網絡上很多配置nginx的rewrite其實是不可用的,如果想運行vephp、yii、thinkphp等MVC框架,在apache下是很容易的,nginx比較麻煩。
下面這個配置是已應用于vephp框架( www.snjht.com ),并且對thinkphp也是可用的。并且window和linux通用,只是要把根目錄替換一下。
它的原理是:如果服務器上存在該腳本文件就直接訪問,如果不存在,則使用MVC框架路由解析。
特分享出來。
server {
listen 80;
server_name www.snjht.com;
#charset koi8-r;
#access_log logs/host.access.log main;
#root /var/www/website; # linux下根目錄
root M:/www/website; #window下根目錄
index index.html index.htm index.php;
location ~ \.(css|js|jpg|jpeg|png|bmp|gif|svg|ttf|woff|woff2|eot|otf|ico|css\.map|min\.map)(.*)$ {
break;
}
location / {
#index index.htm index.html index.php;
#訪問路徑的文件不存在則重寫URL轉交給框架處理
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php/?.*$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#加載Nginx默認"服務器環境變量"配置
#include fastcgi.conf;
include fastcgi_params;
#設置PATH_INFO并改寫SCRIPT_FILENAME,SCRIPT_NAME服務器環境變量
set $fastcgi_script_name2 $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {
set $fastcgi_script_name2 $1;
set $path_info $2;
}
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2;
fastcgi_param SCRIPT_NAME $fastcgi_script_name2;
}
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
如果是apache配置rewrite,則參考這里http://www.snjht.com/jiaocheng/20.html
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/19.html