【应用服务 App Service】 App Service Rewrite 实例 - 反向代理转发功能
问题描述
在使用Azure App Service(应用服务)时,有时候需要在不同的站点之间进行跳转,但是希望通过通过访问同一个域名的方式来实现反向代理。如果创建应用时候选择的是Window服务,这时候可以参考以下的方式配置IIS 的Proxy + Rewrie
如网站一为PHP站点,它的首页是:https://lbphptest.chinacloudsites.cn/, 网站二是Java站点,它的首页是:https://lbjavatest.chinacloudsites.cn/
|
站点一:PHP
|
站点二:JAVA
|
在使用反向代理后,在站点一种配置Proxy代理后,请求就会发送到Java站点,但是URL显示的依旧为PHP站点地址。

设置步骤
一: 准备好两个App Service站点
二:在需要做方向代理的站点种添加applicationHost.xdt和web.config 文件,如以上的例子中使用的是PHP站点作为代理站点。
- 添加ApplicationHost.xdt文件,开启Proxy enable属性为true。文件需要添加在D:\home\site下,与wwwroot目录同级

ApplicationHost.xdt的内容为:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<proxy xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="false" reverseRewriteHostInResponseHeaders="false" />
</system.webServer>
</configuration>
- 添加web.config文件,设置rewrite的规则。

web.config的内容为(高亮部分即为需要配置的跳转站点):
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Proxy" stopProcessing="true">
<match url="^proxy/?(.*)" />
<action type="Rewrite" url="http://lbjavatest.chinacloudsites.cn/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
注:完成以上步骤后,需要重启PHP站点。
参考资料
Web 应用如何实现反向代理转发功能:https://docs.azure.cn/zh-cn/articles/azure-operations-guide/app-service-web/aog-app-service-web-howto-realize-reverse-proxy-and-forward-function
URL Rewrite Module Configuration Reference:https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#redirect-action
Rewrite Rules Overview
A rewrite rule defines the logic of what to compare or match the request URL with, and what to do if the comparison is successful.
Rewrite rules consists of the following parts:
- Pattern – The rule pattern is used to specify either the regular expression or a wildcard pattern that is used to match URL strings.
- Conditions – The optional conditions collection is used to specify additional logical operations to perform if a URL string matches the rule pattern. Within the conditions, you can check for certain values of HTTP headers or server variables, or verify if the requested URL corresponds to a file or directory on a physical file system.
- Action – The action is used to specify what to do if the URL string matches the rule pattern and all the rule conditions are met.
【应用服务 App Service】 App Service Rewrite 实例 - 反向代理转发功能的更多相关文章
- Nginx配置实例-反向代理实例:根据访问的路径跳转到不同端口的服务中
场景 Ubuntu Server 16.04 LTS上怎样安装下载安装Nginx并启动: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/detai ...
- upstream模块实现反向代理的功能
nginx平台初探(100%) — Nginx开发从入门到精通 http://tengine.taobao.org/book/chapter_02.html#id6 nginx的模块化体系结构¶ ng ...
- 记录Nginx实现内容重定向的两种方式:rewrite和反向代理
第一种:rewrite server { listen 80; server_name www.test.org; root /te ...
- nginx之rewrite重写,反向代理,负载均衡
rewrite重写(伪静态): 在地址栏输入xx.com/user-xxx.html, 实际上访问的就是xxx.com/user.php?id=xxx rewrite就这么简单 附上ecshop re ...
- Nginx配置实例-反向代理实现浏览器请求Nginx跳转到服务器某页面
场景 Ubuntu Server 16.04 LTS上怎样安装下载安装Nginx并启动: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/detai ...
- nginx 配置实例-反向代理
反向代理实例一 虚拟机IP:192.168.116.129实现效果:使用 nginx 反向代理,访问 www.123.com 直接跳转到 虚拟机的192.168.116.129:8080 实验代码 ...
- Nginx 笔记(三)nginx 配置实例 - 反向代理、负载均衡、动静分离
个人博客网:https://wushaopei.github.io/ (你想要这里多有) 一.反向代理 反向代理准备工作: (1)在 liunx 系统安装 tomcat,使用默认端口 8080 ...
- nginx证书制作以及配置https并设置访问http自动跳转https(反向代理转发jboss)
nginx证书制作以及配置https并设置访问http自动跳转https 默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译时指定–with-http_ssl_module参数,安装模块依赖 ...
- 【转】Nginx反向代理转发tomcat
http://blog.csdn.net/mlc1218559742/article/details/53117520 最近刚接触nginx,在网上查阅了相关资料,看到最多的形容nginx的词就是反向 ...
随机推荐
- 使用Jasmine和karma对传统js进行单元测试
当你拿到十五年前的一堆javascript的代码,你如何对这堆javascript代码写单元测试呢?于是就有了这篇文章. 注意:不需要装任何现代化js框架,包括angular,react,vue之类的 ...
- 北京数途科技有限公司--EAM MAXIMO介绍
一.EAM概述: EAM( Enterprise Asset Management)即企业资产维护管理系统 ,它是面向资产密集型(Asset-intensive)企业的企业信息化 解决方案的总称,其前 ...
- 3.Kafka集群配置
- 《InnoDB存储引擎》笔记
第1章 Mysql体系结构和存储引擎 1.1 定义数据库和实例 数据库:database,物理的操作系统文件或其他形式文件类型的集合.当使用NDB存储引擎时,数据库文件可能是存放在内存中而不是磁盘之上 ...
- 智慧组织(SO)如何敏捷构建?
人类社会正处于千年未有之变局的关键时刻--互联网.大数据.AI和实体经济深度融合,数据正在重新定义世界并重构财富体系."新旧交织.破立并存",数字经济方兴未艾,传统势力逐步淡出.各 ...
- 对offsetof、 container_of宏和结构体的理解
offsetof 宏 #include<stdio.h> #define offsetoff(type, member) ((int)&((type*)0)->me ...
- spring-boot-route(四)全局异常处理
在开发中,我们经常会使用try/catch块来捕获异常进行处理,如果有些代码中忘记捕获异常或者不可见的一些异常出现,就会响应给前端一些不友好的提示,这时候我们可以使用全局异常处理.这样就不用在代码中写 ...
- 记一次ElementUI源码修改过程
修改目的 使用ElementUI el-tree过程发现选中节点,键盘移动上下键时(key down\key up)el-tree默认高亮移动的节点,业务上需要重写此事件. 从官网发现该事件没有暴露 ...
- 005 01 Android 零基础入门 01 Java基础语法 01 Java初识 05 Eclipse简介
005 01 Android 零基础入门 01 Java基础语法 01 Java初识 05 Eclipse简介 Eclipse是一款集成开发工具--IDE. 集成开发环境(IDE,Integrated ...
- 关于对象的行为、数组、继承和类的高级概念(Java)
1.对象的行为: (1)方法调用栈:所有的方法调用都维护在一个称为调用栈的结构中. 第一个被调用的方法就是main(),该方法是Jvm调用的,因此main()方法总 ...

