军哥,求助YII2怎么伪静态没效果
之前看到1.5测试版本有支持yii2的,所以昨晚弄好环境就睡觉了,早上起来配好 yii2 路由规则后发现打开页面还是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;
include rewrite/yii2.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php-pathinfo.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log off;
}
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
} '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',
],
], 如果只是开伪静态不开pahtinfo模式,把 include enable-php-pathinfo.conf; 改成 include enable-php.conf; 重启nginx 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;
} http://tt.com/web/index.php?r=site%2Findex 好了谢谢军哥,
include enable-php.conf; 我又改回pahtinfo 了一样可以。
我修改了 入口文件web为根目录,后就可以了 ,
root/home/wwwroot/tt.com/web/;
报500错误因为open_basedir限制了访问文件的路径
解决方案是:修改了 fastcgi.conf的open_basedir的路径,修改$document_root变成希望访问的项目文件夹
执行以下命令
cd lnmp1.5
cd tools
./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 |
+-------------------------------------------------------------------+
应该是问你要解锁的路径
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 编辑 ]
页:
[1]