【备忘录】yii2高级模板多个应用启用同一个域名多个栏目
2017-04-12 15:34
453 查看
nginx部署方式,两种写法,本人认为第一种写法没有第二种写法优雅第一种写法配置文件:
server{ listen80; server_nameyouban-dev.jqtest.mopon.cn; rootE:\youban_svn\2.1.0\youban-php\mall; indexindex.phpindex.htmlindex.htm; access_loglogs/youban-dev.jqtest.mopon.cn.access.log; #PC端 location/pc/{ aliasE:\youban_svn\2.1.0\youban-php\mall\website\web; rewrite^(/pc/)/$$1permanent; try_files$uri/website/web/index.php?$args; } location~^/pc/(.+\.(js|json|html|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar))${ access_logoff; expires360d; rewrite^/pc/(.+)$/website/web/$1break; rewrite^/pc/(.+)/(.+)$/website/web/$1/$2break; try_files$uri=404; } #wap手机端 location/wap/{ aliasE:\youban_svn\2.1.0\youban-php\mall\mobile\web; rewrite^(/wap/)/$$1permanent; try_files$uri/mobile/web/index.php?$args; } location~^/wap/(.+\.(js|json|html|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar))${ access_logoff; expires360d; rewrite^/wap/(.+)$/mobile/web/$1break; rewrite^/wap/(.+)/(.+)$/mobile/web/$1/$2break; try_files$uri=404; } #微信端 location/weixin/{ aliasE:\youban_svn\2.1.0\youban-php\mall\frontend\web; rewrite^(/weixin/)/$$1permanent; try_files$uri/frontend/web/index.php?$args; } location~^/weixin/(.+\.(js|json|html|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar))${ access_logoff; expires360d; rewrite^/weixin/(.+)$/frontend/web/$1break; rewrite^/weixin/(.+)/(.+)$/frontend/web/$1/$2break; try_files$uri=404; } #地图 location/map/{ aliasE:\youban_svn\2.1.0\youban-php\mall\maps\web; rewrite^(/weixin/)/$$1permanent; try_files$uri/maps/web/index.php?$args; } location~^/map/(.+\.(js|json|html|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar))${ access_logoff; expires360d; rewrite^/map/(.+)$/maps/web/$1break; rewrite^/map/(.+)/(.+)$/maps/web/$1/$2break; try_files$uri=404; } #passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000 # location~\.php${ rootE:\youban_svn\2.1.0\youban-php\mall; fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name; includefastcgi_params; } #denyaccessto.htaccessfiles,ifApache'sdocumentroot #concurswithnginx'sone # location~/\.ht{ denyall; } }第二种写法配置
server{ listen80; server_nameyouban-dev.jqtest.mopon.cn; #微信站点 location/weixin/{ proxy_set_headerHost$http_host; proxy_redirectoff; proxy_set_headerX-Real-IP$remote_addr; proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for; proxy_passhttp://youban-weixin/;} #wap站点 location/wap/{ proxy_set_headerHost$http_host; proxy_redirectoff; proxy_set_headerX-Real-IP$remote_addr; proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for; proxy_pass http://youban-wap/;} #pc站点 location/pc/{ proxy_set_headerHost$http_host; proxy_redirectoff; proxy_set_headerX-Real-IP$remote_addr; proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for; proxy_pass http://youban-pc/;} #地图站点 location/map/{ proxy_set_headerHost$http_host; proxy_redirectoff; proxy_set_headerX-Real-IP$remote_addr; proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for; proxy_pass http://youban-map/;} }
#微信站点
upstreamyouban-weixin{ server127.0.0.1:8012; } server{ listen8012; rootE:\youban_svn\2.1.0\youban-php\mall\frontend\web; indexindex.phpindex.htmlindex.htm; location/nginx_status { stub_statuson; access_logoff; } location~\.php${ rootE:\youban_svn\2.1.0\youban-php\mall\frontend\web; fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name; includefastcgi_params; } location~.*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires30d; } location~.*\.(js|css)?$ { expires12h; } location~/\. { denyall; } #access_log/home/logs/youban_dev/2.0/weixin.youban-dev.com.log; }
#wap站点
upstreamyouban-wap{ server127.0.0.1:8013; } server{ listen8013; rootE:\youban_svn\2.1.0\youban-php\mall\mobile\web; indexindex.phpindex.htmlindex.htm; location/nginx_status { stub_statuson; access_logoff; } location~\.php${ rootE:\youban_svn\2.1.0\youban-php\mall\mobile\web; fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name; includefastcgi_params; } location~.*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires30d; } location~.*\.(js|css)?$ { expires12h; } location~/\. { denyall; } #access_log/home/logs/youban_dev/2.0/h5.youban-dev.com.log; }
#pc站点
upstreamyouban-pc{
server127.0.0.1:8011;
}server{
listen8011;rootE:\youban_svn\2.1.0\youban-php\mall\website\web;
indexindex.phpindex.htmlindex.htm;
location/nginx_status
{
stub_statuson;
access_logoff;
}
location~\.php${
rootE:\youban_svn\2.1.0\youban-php\mall\website\web;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}
location~.*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires30d;
}
location~.*\.(js|css)?$
{
expires12h;
}
location~/\.
{
denyall;
}
#access_log/home/logs/youban_dev/2.0/web.youban-dev.com.log;
}
#地图站点
upstreamyouban-map{
server127.0.0.1:8014;
}server{
listen8014;rootE:\youban_svn\2.1.0\youban-php\mall\maps\web;
indexindex.phpindex.htmlindex.htm;
location/nginx_status
{
stub_statuson;
access_logoff;
}
location~\.php${
rootE:\youban_svn\2.1.0\youban-php\mall\maps\web;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}
location~.*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires30d;
}
location~.*\.(js|css)?$
{
expires12h;
}
location~/\.
{
denyall;
}
#access_log/home/logs/youban_dev/2.0/web.youban-dev.com.log;
}
OK,将配置文件引入nginx.conf配置文件,就能通过目录访问不同的应用了,如:
微信站点http://www.xxx.com/weixin/
手机wap站点'target='_blank'>http://www.xxx.com/wap/[/code] PC站点'target='_blank'>http://www.xxx.com/pc/[/code] 地图应用'target='_blank'>http://www.xxx.com/map/[/code] warning:无论哪种配置,过后都会影响到Url::to()这个方法,直接重写UrlManager中的createUrl的方法,如下: <?php配置文件中修改:
/**
*User:szliugx@gmail.com
*Date:2017/4/12
*Time:14:06
*/namespacemaps\component;classUrlManagerextends\yii\web\UrlManager
{
/**
*重写URL,以自定义的栏目开始
*@paramarray|string$params
*@returnstring
*/
publicfunctioncreateUrl($params)
{$url=parent::createUrl($params);//TODO:Changetheautogeneratedstub
return\Yii::$app->params["homeUrl"]["map"].ltrim($url,'\\/');;
}
}
相关文章推荐
- yii2高级模板使用一个域名管理前后台
- yii2高级模板使用一个域名管理前后台(亲测可用)
- yii2高级模板使用一个域名管理前后台
- yii2高级模板使用一个域名管理前后台
- yii2高级模板使用一个域名管理前后台(url重写)
- Yii2 高级模板 多域名管理问题
- Yii2 高级版新建一个 Api 应用
- Yii2-高级应用程序模板在同一域名下使用配置
- 安装yii2高级应用模板
- Yii2-高级应用程序模板在同一域名下使用配置
- Yii2 高级版新建一个 Api 应用
- yii2 高级版新建一个应用(api应用为例子)
- Yii2 高级版新建一个 Api 应用
- Yii2-高级应用程序模板在同一域名下使用配置
- Yii2创建高级应用模板+安装扩展
- Creating a Simple CRUD App With Yii2 用 Yii2 创建一个简单的 CRUD (增删改查)应用
- MVC中DisplayFor方法应用模板时的一个问题
- hdu 4002 收获非常大的一个题 多功能大数模板的应用
- 黑马程序员:一个小应用引出的模板设计方法介绍
- phpcms修改栏目配置中的模板设置-模板应用到子栏目不起作用