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 

相关文章

文章浏览阅读3.7k次,点赞2次,收藏5次。Nginx学习笔记一、N...
文章浏览阅读1.7w次,点赞14次,收藏61次。我们在使用容器的...
文章浏览阅读1.4k次。当用户在访问网站的过程中遇到404错误时...
文章浏览阅读2.7k次。docker 和 docker-compose 部署 nginx+...
文章浏览阅读1.3k次。5:再次启动nginx,可以正常启动,可以...
文章浏览阅读3.1w次,点赞105次,收藏182次。高性能:Nginx ...