yii2高级模板使用一个域名管理前后台
yii2的高级模板分为backend和frontend,最开始用yii的时候并没怎么在意,就使用了两个域名分别解析前后台。今天无意间看见
可以使用一个域名指向前后台。
1.修改 advanced/backend/config/main.PHP 文件如下:
return [
'homeUrl' => '/admin',
'components' => [
'request' => [
'baseUrl' => '/admin',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
];
2.同样修改 advanced/frontend/config/main.php 文件:
return [
'homeUrl' => '/',
'components' => [
'request' => [
'baseUrl' => '',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
];
3.配置域名解析
<VirtualHost *:80>
ServerName advanced.loc
ServerAlias www.advanced.loc
DocumentRoot "/path/to/advanced"
<Directory "/path/to/advanced">
AllowOverride All
</Directory>
</VirtualHost>
4.新建一个.htaccess文件,写入一下内容。放在项目根目录advacnced下
# prevent directory listings
Options -Indexes
# follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/admin/$
RewriteRule ^(admin)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin(/.+)?$ /backend/web/$1 [L,PT]
RewriteCond %{REQUEST_URI} ^.*$
RewriteRule ^(.*)$ /frontend/web/$1
5.再次新建一个.htaccess文件,写入一下内容,在frontend和backend分别放一个。
# use mod_rewrite for pretty URL support
RewriteEngine on
# if a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward the request to index.php
RewriteRule . index.php
如果服务器是nginx,则更改nginx.cong文件,写入以下内容,具体路径根据自身实际情况进行修改
server {
charset utf-8;
client_max_body_size 200M;
listen 80; ## listen for ipv4
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
server_name advanced.loc;
root /path/to/advanced;
access_log /path/to/logs/advanced.access.log main buffer=50k;
error_log /path/to/logs/advanced.error.log warn;
location / {
root /path/to/advanced/frontend/web;
try_files $uri /frontend/web/index.php?$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 /path/to/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;
# check your /etc/php5/fpm/pool.d/www.conf to see if PHP-FPM is listening on a socket or port
fastcgi_pass unix:/var/run/php5-fpm.sock; ## listen for socket
#fastcgi_pass 127.0.0.1:9000; ## listen for port
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
try_files $uri =404;
}
#error_page 404 /404.html;
location = /requirements.php {
deny all;
}
location ~ \.(ht|svn|git) {
deny all;
}
}
yii2高级模板使用一个域名管理前后台的更多相关文章
- Yii2 高级模板不使用Apache配置目录,将前后台入口移到根目录
刚刚入手Yii2高级模板不久,部署项目时,得部署2个应用,个人感觉很繁琐,就将前后台入口文件全部拿到项目根目录.但是一看,完了,出错了!找教程找不到,还是自己解决吧 为了以后好升级,不改变Yii2核心 ...
- Yii2高级模板vendor和application非同级目录部署
上面是Yii2的高级模板,当我们有多个application的时候,这种高级模板可以可以提供很好的扩展性,多个application共用一份YII2框架,默认情况下,框架和application是在同 ...
- Yii2 高级模板 多域名管理问题
现在在网站中有这种情况,比如有一个 http://frontend.com/tv 需要根据判断用户的 User Agent ,如果用户是手机浏览器的话,则跳转到 http://mobile.com/t ...
- 【备忘录】yii2高级模板多个应用启用同一个域名多个栏目
nginx部署方式,两种写法,本人认为第一种写法没有第二种写法优雅 第一种写法配置文件: server { listen ; server_name youban-dev.jqtest.mopon.c ...
- Yii2高级模板的安装
1.通过composer 安装高级版 C:wampwwwyii>composer create-project --prefer-dist yiisoft/yii2-app-advanced a ...
- yii2高级模板安装
通过 Composer 安装 如果还没有安装 Composer,在 Linux 和 Mac OS X 中可以运行如下命令: curl -sS https://getcomposer.org/insta ...
- 对于 yii2 高级模板 生成文件入口
安装的 advanced 模板web下是没有index.php 方法: 在advanced 目录下有个init.bat 应用程序 双击即可如下 查看advanced 目录 (刷新)如下 已有:
- Yii2 高级模板添加更多Application
单独的前端和后端有时是不够的. 如果需要额外的应用程序,例如博客blog: 1.将frontend复制到blog,环境/ dev / frontend到environments / dev / blo ...
- Yii2 高级版新建一个 Api 应用
原文地址:http://www.getyii.com/topic/28 先在项目的根目录下复制一份 backend 为 api: cp backend/ api -r 拷贝 api 环境 cp -a ...
随机推荐
- 2017-07-06(grep man apropos )
grep 格式 grep [选项] 字符串 文件名 选项 -i 忽略大小写 -v 排除指定字符串 作用 在文件中查找字符串 例子 grep "size" anaconda- ...
- 定时任务schedule(spring boot )
1. 定时任务实现方式:SpringBoot自带的Scheduled,可以将它看成一个轻量级的Quartz,而且使用起来比Quartz简单许多,本文主要介绍. 执行方式:单线程(串行)多线程(并行) ...
- servlet 监听器分类
http://blog.csdn.net/cxg200888/article/details/77894842
- PDO错误调试
在服务器上用PDO操作数据库,怎么都获取不到数据,query语句返回null,但是同样的代码在本地运行无误.SO,开始找bug. <?php $host='localhost'; $dbname ...
- CGroup Namspace
CGroup 介绍 CGroup 是 Control Groups 的缩写,是 Linux 内核提供的一种可以限制.记录.隔离 进程组 (process groups) 所使用的物力资源 (如 cpu ...
- awk脚本使用的几种方法
1. awk名包含在文件内 [root@nhserver1 08]# cat sample.txtaaabbbccc [root@nhserver1 08]# cat readsample.awkaw ...
- samephore()信号量跨线程通信
samephore1: #include <stdio.h> #include <stdlib.h> #include <Windows.h> ] = " ...
- 关于scanf,gets
1.用了gets后,假如你没有输入任何东西直接[enter],它将执行下一条命令 2.用了scanf后,直接按了[enter],它将换行并等待你的输入,直到你输入非[enter],再执行下一条命令. ...
- 知识点干货—多线程同步【6】之synchronized
"明日复明日,明日何其多. 我生待明日,万事成蹉跎. 世人若被明日累,春去秋来老将至. 朝看水东流,暮看日西坠. 百年明日能几何?请君听我明日歌. 明日复明日,明日何其多! 日日待明日,万世 ...
- Spring MVC执行的流程
1.Spring MVC应用的开发步骤 a.在web.xml文件中定义前端控制器DispatcherServlet来拦截用户请求.由于Web应用是基于请求/响应架构的应用,所以 不管哪个MVC Web ...