nginx部署方式,两种写法,本人认为第一种写法没有第二种写法优雅

第一种写法配置文件:

    server {
listen ;
server_name youban-dev.jqtest.mopon.cn;
root E:\youban_svn\2.1.\youban-php\mall;
index index.php index.html index.htm; access_log logs/youban-dev.jqtest.mopon.cn.access.log; #PC端
location /pc/ {
alias E:\youban_svn\2.1.\youban-php\mall\website\web; rewrite ^(/pc/)/$ $ permanent;
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_log off;
expires 360d; rewrite ^/pc/(.+)$ /website/web/$ break;
rewrite ^/pc/(.+)/(.+)$ /website/web/$/$ break;
try_files $uri =;
} #wap手机端
location /wap/ {
alias E:\youban_svn\2.1.\youban-php\mall\mobile\web; rewrite ^(/wap/)/$ $ permanent;
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_log off;
expires 360d; rewrite ^/wap/(.+)$ /mobile/web/$ break;
rewrite ^/wap/(.+)/(.+)$ /mobile/web/$/$ break;
try_files $uri =;
} #微信端
location /weixin/ { alias E:\youban_svn\2.1.\youban-php\mall\frontend\web; rewrite ^(/weixin/)/$ $ permanent;
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_log off;
expires 360d; rewrite ^/weixin/(.+)$ /frontend/web/$ break;
rewrite ^/weixin/(.+)/(.+)$ /frontend/web/$/$ break;
try_files $uri =;
} #地图
location /map/ { alias E:\youban_svn\2.1.\youban-php\mall\maps\web; rewrite ^(/weixin/)/$ $ permanent;
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_log off;
expires 360d; rewrite ^/map/(.+)$ /maps/web/$ break;
rewrite ^/map/(.+)/(.+)$ /maps/web/$/$ break;
try_files $uri =;
} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
location ~ \.php$ {
root E:\youban_svn\2.1.\youban-php\mall;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}

第二种写法配置

server {
listen ;
server_name youban-dev.jqtest.mopon.cn;
#微信站点
location /weixin/ {
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://youban-weixin/;
}
#wap站点
location /wap/ {
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://youban-wap/;
}
#pc站点
location /pc/ {
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://youban-pc/;
}
#地图站点
location /map/ {
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://youban-map/;
} }
#微信站点
upstream youban-weixin {
server 127.0.0.1:;
} server {
listen ;
root E:\youban_svn\2.1.\youban-php\mall\frontend\web;
index index.php index.html index.htm;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ \.php$ {
root E:\youban_svn\2.1.\youban-php\mall\frontend\web;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
#access_log /home/logs/youban_dev/2.0/weixin.youban-dev.com.log;
}
#wap站点
upstream youban-wap {
server 127.0.0.1:;
} server {
listen ; root E:\youban_svn\2.1.\youban-php\mall\mobile\web;
index index.php index.html index.htm;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ \.php$ {
root E:\youban_svn\2.1.\youban-php\mall\mobile\web;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
#access_log /home/logs/youban_dev/2.0/h5.youban-dev.com.log;
}
 
#pc站点
upstream youban-pc {
server 127.0.0.1:;
} server {
listen ; root E:\youban_svn\2.1.\youban-php\mall\website\web;
index index.php index.html index.htm;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ \.php$ {
root E:\youban_svn\2.1.\youban-php\mall\website\web;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
#access_log /home/logs/youban_dev/2.0/web.youban-dev.com.log;
}
 
#地图站点
upstream youban-map {
server 127.0.0.1:;
} server {
listen ; root E:\youban_svn\2.1.\youban-php\mall\maps\web;
index index.php index.html index.htm;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ \.php$ {
root E:\youban_svn\2.1.\youban-php\mall\maps\web;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
#access_log /home/logs/youban_dev/2.0/web.youban-dev.com.log;
}


OK,将配置文件引入nginx.conf配置文件,就能通过目录访问不同的应用了,如:
微信站点
http://www.xxx.com/weixin/
手机wap站点
http://www.xxx.com/wap/
PC站点
http://www.xxx.com/pc/
地图应用
http://www.xxx.com/map/

warning:无论哪种配置,过后都会影响到Url::to()这个方法,直接重写UrlManager中的createUrl的方法,如下:

<?php
/**
* User: szliugx@gmail.com
* Date: 2017/4/12
* Time: 14:06
*/ namespace maps\component; class UrlManager extends \yii\web\UrlManager
{
/**
* 重写URL,以自定义的栏目开始
* @param array|string $params
* @return string
*/
public function createUrl($params)
{ $url = parent::createUrl($params); // TODO: Change the autogenerated stub
return \Yii::$app->params["homeUrl"]["map"].ltrim($url, '\\/');;
}
}

配置文件中修改:


 
 

【备忘录】yii2高级模板多个应用启用同一个域名多个栏目的更多相关文章

  1. Yii2 高级模板不使用Apache配置目录,将前后台入口移到根目录

    刚刚入手Yii2高级模板不久,部署项目时,得部署2个应用,个人感觉很繁琐,就将前后台入口文件全部拿到项目根目录.但是一看,完了,出错了!找教程找不到,还是自己解决吧 为了以后好升级,不改变Yii2核心 ...

  2. Yii2高级模板vendor和application非同级目录部署

    上面是Yii2的高级模板,当我们有多个application的时候,这种高级模板可以可以提供很好的扩展性,多个application共用一份YII2框架,默认情况下,框架和application是在同 ...

  3. yii2高级模板使用一个域名管理前后台

    yii2的高级模板分为backend和frontend,最开始用yii的时候并没怎么在意,就使用了两个域名分别解析前后台.今天无意间看见 可以使用一个域名指向前后台. 1.修改 advanced/ba ...

  4. Yii2高级模板的安装

    1.通过composer 安装高级版 C:wampwwwyii>composer create-project --prefer-dist yiisoft/yii2-app-advanced a ...

  5. yii2高级模板安装

    通过 Composer 安装 如果还没有安装 Composer,在 Linux 和 Mac OS X 中可以运行如下命令: curl -sS https://getcomposer.org/insta ...

  6. 对于 yii2 高级模板 生成文件入口

    安装的 advanced 模板web下是没有index.php 方法: 在advanced 目录下有个init.bat 应用程序  双击即可如下 查看advanced 目录 (刷新)如下 已有:

  7. Yii2 高级模板添加更多Application

    单独的前端和后端有时是不够的. 如果需要额外的应用程序,例如博客blog: 1.将frontend复制到blog,环境/ dev / frontend到environments / dev / blo ...

  8. Yii2 高级模板 多域名管理问题

    现在在网站中有这种情况,比如有一个 http://frontend.com/tv 需要根据判断用户的 User Agent ,如果用户是手机浏览器的话,则跳转到 http://mobile.com/t ...

  9. yii2高级版账号密码问题

    yii2高级版默认后台没有密码,生成账号密码步骤: 1. CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` ...

随机推荐

  1. 控制台小游戏-贪吃蛇,c++和c#版

    说是c++版,其实只是用到了c++的cout和cin而已.这是我做的第二个控制台游戏,基本上每一行代码都加上了注释. 游戏嘛,我觉得重要的是了解他的思想,所以后期学了面向对象之后这个游戏的代码我也没有 ...

  2. IOS-OC 编码建议

    “神在细节之中” Objective-C 是 C 语言的扩展,增加了动态类型和面对对象的特性.它被设计成具有易读易用的,支持复杂的面向对象设计的编程语言.它是 Mac OS X 以及 iPhone 的 ...

  3. Diff Two Arrays

    比较两个数组,然后返回一个新数组,该数组的元素为两个给定数组中所有独有的数组元素.换言之,返回两个数组的差异. 这是一些对你有帮助的资源: Comparison Operators Array.sli ...

  4. 十四、dbms_obfuscation_toolkit(用于加密和解密应用数据)

    1.概述 作用:用于加密和解密应用数据,另外还可以生成密码检验和.通过加密输入数据,可以防止黑客或其他用户窃取私有数据;而通过结合使用加密和密码检验和,可以防止黑客破坏初加密的数据.当使用该包加密数据 ...

  5. CSS3 文本超出后显示省略号...

    纯用CSS实现,主要采用代码 overflow:hidden; text-overflow:ellipsis;//这是让文本溢出后,显示成省略号. white-space:nowrap;//禁止自动换 ...

  6. Linux输入输出管理

      一.系统输入输出的理解 运行一个程序时,需要从某个位置读取输入信息,然后CPU处理,最后将输出 显示在屏幕或文件中:其中,某个位置相当于输入设备,屏幕或文件为输出设备. 标准输入:stdin,默认 ...

  7. Java多线程编程实战指南(核心篇)读书笔记(二)

    (尊重劳动成果,转载请注明出处:http://blog.csdn.net/qq_25827845/article/details/76651408冷血之心的博客) 博主准备恶补一番Java高并发编程相 ...

  8. yxy-插入formid-并发/压力(入参的变量化)

    1.抓取接口如下 2.该接口为插入数据库操作,由于前段操作频繁,就简单压测一下 接口中formId.accountId.openId为变量 formId为随机生成插入:accountId.openId ...

  9. vscode+Firefox实现前端移动真机测试

    需要配件: 1.安装有火狐浏览器的移动端(手机); 2.安装有火狐浏览器和vscode的pc(电脑); 3.在vscode安装Live Server 插件 4.安装之后vscode右下角会有Go Li ...

  10. python中的字典两种遍历方式

    dic = {"k1":"v1", "k2":"v2"} for k in dic: print(dic[K]) for ...