Yii 2.0 在Nginx下的urlManager配置

作者: php 发布时间: 2017-05-18 浏览: 3040 次 编辑

apache和nginx比起来,我更倾向nginx,占用资源少,且性能高,不管是开发还是生产环境都很好用。那么,如何配置nginx让其支持yii2.0的访问呢?

1、在\config\web.php中加入urlManager部分

'urlManager' => [
      'enablePrettyUrl' => true,
      'showScriptName' => false,
//    'suffix' => '.html',  //后缀
      'rules' => [],
],

2、在nginx下修改配置

location / {
      index index.html index.htm index.php;
      if (!-e $request_filename){
          rewrite ^/(.*) /index.php last;
      }
}



配置好以后重启nginx(sudo nginx -s reload)

之前访问url:localhost/index.php?r=site/about

配置好以后:http://localhost/site/about 就可以这样访问了。这样是不是顺眼多了