nginx 判断手机端跳转_Nginx系列:配置跳转的常用方式

阅读文本大概需要3分钟。

       随着应用服务的增多,服务可能部署在不同的服务器上。这些服务有可能存在IP端口Port、请求的ContextPath等一样的情况,怎么合理的配置他们的跳转呢?下面介绍三种常见的跳转方式。

0x01:根据不同域名判断跳转不同服务

就是根据在nginx.conf配置的server_name与域名或者(或者IP)匹配跳转不同的服务。

#当客户端访问www.domain.com,监听端口号为80,直接跳转到data/www目录下文件
server {
    listen       80;
       server_name  www.domain.com;
       location / {
          root   data/www;
          index  index.html index.htm;
    }
 }
 #当客户端访问bbs.domain.com,监听端口号为80,直接跳转到data/bbs目录下文件
server {
     listen       80;
     server_name  bbs.domain.com;
     location / {
         root   data/bbs;
         index  index.html index.htm;
     }
}

0x02:根据不同端口判断跳转不同服务

就是根据在nginx.conf配置的listen指令匹配跳转不同的服务。

#当客户端访问www.domain.com,监听端口号为8081,直接跳转到data/www目录下文件
server {
      listen       8081;
      server_name  www.domain.com;
      location / {
          root   data/www;
          index  index.html index.htm;
      }
}

#当客户端访问www.domain.com,监听端口号为8082,直接跳转到data/bbs目录下文件
server {
      listen       8082;
      server_name  www.domain.com;
      location / {
          root   data/bbs;
          index  index.html index.htm;
      }
}

0x03:根据链接的ContextPath不同跳转不同的服务器

主要根据每个应用服务器的ContextPath的普通,匹配跳转到不同的服务器。

#服务创建监听的端口号
server {
    #监听的端口号
    listen       80;
    #服务名称
    server_name  www.domain.com;
   # 匹配项目名称为bbs开头
   location /bbs/ {
       #  配置反向代理
       proxy_pass http://192.168.1.188:8081/;
       index  index.html index.htm;
   }
   # 匹配项目名称为blog开头
   location /blog/ {
        # 配置反向代理
        proxy_pass http://192.168.1.188:8082/;
       index  index.html index.htm;
   }
}

往期精彩

01 Sentinel如何进行流量监控

02 Nacos源码编译

03 基于Apache Curator框架的ZooKeeper使用详解

04 spring boot项目整合xxl-job

05 互联网支付系统整体架构详解

关注我

每天进步一点点

6970ee7245ea07e62aa33e0a4524244d.png

喜欢!在看 ☟
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值