您的位置:首页 > 编程语言 > PHP开发

【备忘录】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_passhttp://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_passhttp://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_passhttp://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,'\\/');;
}
}
配置文件中修改:


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: