【问题标题】:How can I configure my Web App in Windows Azure to redirect the requests to different VMs based on the request URL?如何在 Windows Azure 中配置我的 Web 应用程序以根据请求 URL 将请求重定向到不同的 VM?
【发布时间】:2016-08-28 04:22:45
【问题描述】:

在 Microsoft Azure 上,我有两个运行相同 RESTful 服务的 Linux 虚拟机(一个是 Ubuntu,另一个是 CentOS)。这两个虚拟机在同一个 vnet 中运行。

现在我创建了一个 Web 应用程序,并希望这个 Web 应用程序根据请求 URL 的格式将客户端请求重定向到这两个虚拟机,例如:

  • http://myapp.azurewebsite.com:8080/api/customers进来时,请求会被重定向到Ubuntu服务器
  • http://myapp.azurewebsite.com:8080/api/orders进来时,请求应该被重定向到CentOS服务器

如何在 Azure 中执行此操作?

谢谢!

【问题讨论】:

    标签: linux azure redirect


    【解决方案1】:

    看看Azure Application Gateway,它是一个面向外部的第 7 层负载均衡器。它具有您可能会觉得有用的各种功能。

    根据您的要求,应用程序网关允许您创建服务器池,这些服务器池将根据 URL 将请求定向到它们。有关如何设置的更多信息,请参阅"Create an application gateway using URL based routing"

    【讨论】:

      【解决方案2】:

      Azure webapp 在 IIS 上运行。您可以使用 URL 重写在 Web.config 中创建规则,将一个 URL 重写为另一个。

      <?xml version="1.0" encoding="utf-8" ?>
      <configuration>
          <system.webServer>
              <rewrite>
                  <rules>
                      <rule name="Redirect request to Ubuntu">
                          <match url=".*" />
                          <conditions>
                              <add input="{HTTP_HOST}" pattern="^www.myapp.azurewebsite.com:8080/api/customers$" />
                          </conditions>
                          <action type="Redirect" url="http://ubuntu-server/{R:0}" redirectType="Permanent" />
                      </rule>
                      <rule name="Redirect request to CentOS">
                          <match url=".*" />
                          <conditions>
                              <add input="{HTTP_HOST}" pattern="^www.myapp.azurewebsite.com:8080/api/orders$" />
                          </conditions>
                          <action type="Redirect" url="http://CentOS-server/{R:0}" redirectType="Permanent" />
                      </rule>          
                  </rules>
              </rewrite>
          </system.webServer>
      </configuration>
      

      【讨论】:

      • 这似乎是个好主意。我会试一试。此外,如果我需要不仅基于 URL 分发请求,还需要基于 VM 工作负载,我应该在 Azure 中做什么来实现这一点?
      • 目前对于两个VM,每个请求都会被重定向到某个VM,所以不需要添加工作负载解决方案。但是如果你有两个以上的虚拟机并且多个虚拟机可以响应同一个请求,你可以试试load balancer
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-01
      • 2011-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-19
      相关资源
      最近更新 更多