2017-08-28 17:39:56 2863次浏览 1条回答 0 悬赏 10 金钱
  • 环境:nginx
  • 版本:yii2.0
  • 前后台共用一个域名
  • 前台访问地址 my.yii.com
  • 后台访问地址 my.yii.com/admin
  • 开启urmanager 后台(admin) debug工具消失,gii生成model时报如下错误:“Bad Request (#400): Missing required parameters: id, file”。
  • urlManager 配置如下:
    'urlManager' => [
              'enablePrettyUrl' => true,  //美化url==ture
              'enableStrictParsing' => false,  //不启用严格解析
              'showScriptName' => false,   //隐藏index.php
              'rules' => [
              ],
    ],
    
  • nginx 配置如下:

    server {
      charset utf-8;
      client_max_body_size 128M;
    
      listen 80; ## listen for ipv4
      #listen [::]:80 default_server ipv6only=on; ## listen for ipv6
    
      server_name my.yii.com;
      root        /var/www/html/advanced/;
      index       index.php;
    
      access_log  /var/www/html/advanced/log/access.log;
      error_log   /var/www/html/advanced/log/error.log;
    
      location / {
          root  /var/www/html/advanced/frontend/web;
          try_files  $uri /frontend/web/index.php$is_args$args;
    
          location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
              access_log  off;
              expires  360d;
              try_files  $uri =404;
          }
      }
    
      location ~ \.php$ {
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_pass 127.0.0.1:9000;
          try_files $uri =404;
      }
    
      location = /requirements.php {
          deny all;
      }
    
      location ~* /\. {
          deny all;
      }
    }
    

补充于 2017-08-29 13:54

试过了,不可以,应该是我nginx配置有问题,但找不到正确的配置方式。我新建了一个api应用,未开启url美化的情况下样式加载失败,开启url美化报404;
错误文本如下:

  • Failed to load resource: the server responded with a status of 404 (Not Found),
  • http://my.yii.com/api/assets/3353d214/css/bootstrap.css(这个地址有问题,但是不知道在哪里改)
    nginx配置如下:

    server {
      charset utf-8;
      client_max_body_size 128M;
    
      listen 80; ## listen for ipv4
      #listen [::]:80 default_server ipv6only=on; ## listen for ipv6
    
      server_name my.yii.com;
      root        /var/www/html/advanced/;
      index       index.php;
    
      access_log  /var/www/html/advanced/log/access.log;
      error_log   /var/www/html/advanced/log/error.log;
    
      location / {
          root  /var/www/html/advanced/frontend/web;
          try_files  $uri /frontend/web/index.php$is_args$args;
    
          # avoiding processing of calls to non-existing static files by Yii
          location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
              access_log  off;
              expires  360d;
              try_files  $uri =404;
          }
      }
    
      location /admin {
          alias  /var/www/html/advanced/backend/web;
    
          rewrite  ^(/admin)/$ $1 permanent;
          try_files  $uri /backend/web/index.php?$args;
      }
    
      # avoiding processing of calls to non-existing static files by Yii
      location ~ ^/admin/(.+\.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar))$ {
          access_log  off;
          expires  360d;
    
          rewrite  ^/admin/(.+)$ /backend/web/$1 break;
          rewrite  ^/admin/(.+)/(.+)$ /backend/web/$1/$2 break;
          try_files  $uri =404;
      }
    
      location ~ \.php$ {
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_pass unix:/run/php/php7.0-fpm.sock;
          try_files $uri =404;
      }
    
      location = /requirements.php {
          deny all;
      }
    
      location ~* /\. {
          deny all;
      }
    }
    

  • 回答于 2017-08-29 11:28 举报

    debug应该是关闭了开发者模式或ip限制
    在 main-local.php

    //开发模式才会生效.一般生产环境都会选择关闭
    //在index.php开启或关闭
    if (YII_ENV_DEV) {
        // configuration adjustments for 'dev' environment
        $config['bootstrap'][] = 'debug';
        $config['modules']['debug'] = [
            'class' => 'yii\debug\Module',
            //默认是 127.0.0.1 或 ::1
    
            'allowedIPs' => ['*']	//允许所有ip, 也可以设定某个ip或ip段
    
            //更多的配置可以看 /vendor/yiisoft/yii2-debug/Module.php
        ];
    

    至于gii就不清楚,信息太少.

您需要登录后才可以回答。登录 | 立即注册
alvin_cn
助理

alvin_cn

注册时间:2017-08-03
最后登录:2018-10-09
在线时长:11小时37分
  • 粉丝0
  • 金钱15
  • 威望0
  • 积分125

热门问题