VPS侦探论坛

 找回密码
 注册
查看: 3604|回复: 5

军哥,求助YII2怎么伪静态没效果

[复制链接]
发表于 2018-4-1 07:11:52 | 显示全部楼层 |阅读模式

之前看到1.5测试版本有支持yii2的,所以昨晚弄好环境就睡觉了,
早上起来配好 yii2 路由规则后  发现打开页面还是404



  1. server
  2.     {
  3.         listen 80;
  4.         #listen [::]:80;
  5.         server_name tt.com ;
  6.         index index.html index.htm index.php default.html default.htm default.php;
  7.         root  /home/wwwroot/tt.com;

  8.         include rewrite/yii2.conf;
  9.         #error_page   404   /404.html;

  10.         # Deny access to PHP files in specific directory
  11.         #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

  12.         include enable-php-pathinfo.conf;

  13.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  14.         {
  15.             expires      30d;
  16.         }

  17.         location ~ .*\.(js|css)?$
  18.         {
  19.             expires      12h;
  20.         }

  21.         location ~ /.well-known {
  22.             allow all;
  23.         }

  24.         location ~ /\.
  25.         {
  26.             deny all;
  27.         }

  28.         access_log off;
  29.     }
复制代码



  1. location / {
  2.     # Redirect everything that isn't a real file to index.php
  3.     try_files $uri $uri/ /index.php$is_args$args;
  4. }
复制代码
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2018-4-1 07:12:14 | 显示全部楼层


'urlManager' => [
            'enablePrettyUrl' => true,  //美化url==ture
            'enableStrictParsing' => false,  //不启用严格解析
            'showScriptName' => false,   //隐藏index.php
            'rules' => [
                '<module:\w+>/<controller:\w+>/<id:\d+>' => '<module>/<controller>/view',
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
            ],
        ],
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2018-4-1 09:59:11 | 显示全部楼层

如果只是开伪静态不开pahtinfo模式,把 include enable-php-pathinfo.conf; 改成 include enable-php.conf; 重启nginx
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2018-4-1 10:35:34 | 显示全部楼层



http://tt.com/web/site/index

还是404呢


server
    {
        listen 80;
        #listen [::]:80;
        server_name tt.com;
        index index.html index.htm index.php default.html default.htm default.php;
        root /home/wwwroot/tt.com/;

        包括rewrite / yii2.conf;
        #error_page 404 /404.html;

        #拒绝访问特定目录中的PHP文件#
        location〜/(wp-content|uploads|wp-includes|images)/.*\.php$ {deny all; }

        include enable-php.conf;

        位置〜。* \。(gif | jpg | jpeg | png | bmp | swf)$
        {
            expires 30d;
        }

        location〜。* \。(js | css)?$
        {
            到期12h;
        }

        location〜/.well-known {
            allow all;
        }

        location〜/ \。
        {
            否认所有;
        }

        access_log off;
    }
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2018-4-1 10:37:40 | 显示全部楼层

http://tt.com/web/index.php?r=site%2Findex

军哥运维代购:http://shop63846532.taobao.com/

 楼主| 发表于 2018-4-1 11:34:10 | 显示全部楼层

好了  谢谢军哥,

include enable-php.conf; 我又改回pahtinfo 了  一样可以。

我修改了 入口文件web为根目录,后就可以了 ,
root  /home/wwwroot/tt.com/web/;
报500错误因为open_basedir限制了访问文件的路径
解决方案是:修改了 fastcgi.conf的open_basedir的路径,修改$document_root变成希望访问的项目文件夹
执行以下命令
  1. cd lnmp1.5
  2. cd tools
  3. ./remove_open_basedir_restriction.sh
复制代码

提示
+-------------------------------------------------------------------+
|   Remove open_basedir restrication for LNMP, Written by Licess    |
+-------------------------------------------------------------------+
|       A tool to remove open_basedir restrication for LNMP         |
+-------------------------------------------------------------------+
|       For more information please visit https://lnmp.org          |
+-------------------------------------------------------------------+
|          Usage: ./remove_open_basedir_restrication.sh             |
+-------------------------------------------------------------------+

应该是问你要解锁的路径
  1. Enter website root directory: /home/wwwroot/tt.com
复制代码

最后config/web.php
加上

    'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [
        'login' => 'site/login',
   ],
],

就可以了

就是不知道这样 解锁了 防跨目录还有效吗  安全吗


应该比新建一个index放根目录 再引入web/index.php 安全吧

[ 本帖最后由 蛋蛋的蛋 于 2018-4-1 11:41 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-24 11:30 , Processed in 0.027219 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表