加入收藏 | 设为首页 | 会员中心 | 我要投稿 阜阳站长网 (https://www.0558zz.com/)- 科技、建站、内容创作、云计算、网络安全!
当前位置: 首页 > 运营中心 > Nginx > 正文

nginx要怎么配置rewrite才能运行vephp、yii和thinkphp等MVC框架?

发布时间:2020-07-03 11:10:02 所属栏目:Nginx 来源:互联网
导读:介绍《nginx要怎么配置rewrite才能运行vephp、yii和thinkphp等MVC框架?》开发教程,希望对您有用。

《nginx要怎么配置rewrite才能运行vephp、yii和thinkphp等MVC框架?》要点:
本文介绍了nginx要怎么配置rewrite才能运行vephp、yii和thinkphp等MVC框架?,希望对您有用。如果有疑问,可以联系我们。

网络上很多配置nginx的rewrite其实是不可用的,如果想运行vephp、yii、thinkphp等MVC框架,在apache下是很容易的,nginx比较麻烦。


下面这个配置是已应用于vephp框架( www.jb51.cc  ),并且对thinkphp也是可用的。并且window和linux通用,只是要把根目录替换一下。

它的原理是:如果服务器上存在该脚本文件就直接访问,如果不存在,则使用MVC框架路由解析。

特分享出来。


server {

     listen     80;

     server_name www.jb51.cc;

   

     #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.jb51.cc/jiaocheng/20.html 

(编辑:阜阳站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读