将yii2高级模板的入口文件移到根目录 ,以及nginx对于Yii2的前后台的配置
2018-03-17 13:34
483 查看
一、将yii2高级模板的入口文件移到根目录
打开/var/www/html/yii2advanced/frontend/web 文件夹,将里面的index.php文件复制(或剪切)至项目根目录/var/www/html/yii2advanced 。然后编辑里面的内容为:<?php defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev'); require(__DIR__ . '/vendor/autoload.php'); require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php'); require(__DIR__ . '/common/config/bootstrap.php'); require(__DIR__ . '/frontend/config/bootstrap.php'); $config = yii\helpers\ArrayHelper::merge( require(__DIR__ . '/common/config/main.php'), require(__DIR__ . '/common/config/main-local.php'), require(__DIR__ . '/frontend/config/main.php'), require(__DIR__ . '/frontend/config/main-local.php') ); $application = new yii\web\Application($config); $application->run();然后再修改/var/www/html/yii2advanced/frontend/config 里的main.php文件,在component里加入
'assetManger' => [ 'basePath' => '@webroot/frontend/web/assets', 'baseUrl' => '@web/frontend/web/assets' ],整个main.php应该为:
<?php$params = array_merge(require(__DIR__ . '/../../common/config/params.php'),require(__DIR__ . '/../../common/config/params-local.php'),require(__DIR__ . '/params.php'),require(__DIR__ . '/params-local.php'));return ['id' => 'app-frontend','basePath' => dirname(__DIR__),'bootstrap' => ['log'],'controllerNamespace' => 'frontend\controllers','components' => ['assetManger' => [ 'basePath' => '@webroot/frontend/web/assets', 'baseUrl' => '@web/frontend/web/assets' ],'user' => ['identityClass' => 'common\models\User','enableAutoLogin' => true,],'log' => ['traceLevel' => YII_DEBUG ? 3 : 0,'targets' => [['class' => 'yii\log\FileTarget','levels' => ['error', 'warning'],],],],'errorHandler' => ['errorAction' => 'site/error',],],'params' => $params,];最后修改X:/var/www/html/yii2advanced/frontend/assets 里的AppAsset.php文件,将里面的:
public $css = ['css/site.css',];修改为:
public $css = ['frontend/web/css/site.css',];后台修改方法是将/var/www/html/yii2advanced/backend/web 里的index.php文件夹复制(剪切)至根目录并重命名为admin.php,其他修改地方与上述类似,只是将frontend改为backend即可。
二、nginx对于Yii2的前后台的配置
将/etc/nginx/sites-available/default的内容修改为server {
listen 80 default_server; listen [::]:80 default_server;
# SSL configuration # # listen 443 ssl default_server; # listen [::]:443 ssl default_server; # # Note: You should disable gzip for SSL traffic. # See: https://bugs.debian.org/773332 # # Read up on ssl_ciphers to ensure a secure configuration. # See: https://bugs.debian.org/765782 # # Self signed certs generated by the ssl-cert package # Don't use them in a production server! # # include snippets/snakeoil.conf; root /var/www/html/yii2advanced; # Add index.php to the list if you are using PHP index index.html index.php index.htm index.nginx-debian.html; server_name _; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. # try_files $uri $uri/ =404; try_files $uri $uri/ /index.php?$args; } location /admin { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. # try_files $uri $uri/ =404; try_files $uri $uri/ /admin.php?$args; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { include snippets/fastcgi-php.conf; # # # With php7.0-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php7.0-fpm: fastcgi_pass unix:/run/php/php7.0-fpm.sock; }
# deny access to .htaccess files, if Apache's document root # concurs with nginx's one #location ~ /\.ht { # deny all; #}}这样,你就可以用http://localhost访问前台,用http://localhost/admin.php访问后台了
相关文章推荐
- Yii2 高级模板不使用Apache配置目录,将前后台入口移到根目录
- Yii2 高级模板不使用Apache配置目录,将前后台入口移到根目录
- yii2 - 2: yii2配置 - 配置nginx 初始化yii2高级模板 访问路径
- nginx对于Yii2的前后台的配置
- nginx配置tp5的pathinfo模式并隐藏后台入口文件
- 对于ThinkPHP入口文件以及模块目录结构的学习
- thinkphp的nginx配置,以及重写隐藏index.php入口文件
- CentOS下常用配置文件和命令以及目录结构备注
- Yii2简介以及高级模板安装
- VNC XEN 双鼠标问题 以及 使用 virt-manager 工具创建的 Xen 虚拟机配置文件不在 /etc/xen/ 目录中了
- Yii2-高级应用程序模板在同一域名下使用配置
- nginx 流媒体 flv 播放 以及上传大小 配置文件设置
- centos下配置nginx使其支持tp5的pathinfo,隐藏入口文件
- nginx 配置禁止访问目录或文件
- nginx.config配置文件模板
- centos7 安装LNMP(php7)之 nginx php-fpm yum安装以及配置文件修改
- 如何配置nginx,从而可以访问网站根目录的文件
- nginx禁止用户访问隐藏文件和.htaccess文件 .htaccess文件(或者”分布式配置文件”)提供了针对目录改变配置的方法, 即,在一个特定的文档目录中放置一个包含一个或多个指令的文件, 以
- Yii2框架Nginx配置以及修改fastcgi.conf实现URL美化