将子域映射到虚拟目录 Azure WebApps [英] Map subdomain to virtual directory Azure WebApps

查看:18
本文介绍了将子域映射到虚拟目录 Azure WebApps的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在单个 Azure WebApp 中托管多个网站,而不是让多个 Web 应用程序各自托管一个网站.这些站点中的每一个都相当小,但为了满足 Azure 的 SLA 要求,我们需要为我们的生产环境使用多个实例扩展服务器,这就是合并站点的原因.

I am attempting to host multiple websites in a single Azure WebApp rather than having multiple web apps each hosting a site. Each of these sites is rather small, but in order to meet the requirements of the SLA with Azure, we need to have the server scaled with more than one instance for our Production environment, thus the reasoning for combining sites.

在研究了这个主题之后,我已经使用我们的 Azure 帐户进行了以下设置.

After researching this topic, I have got the following setup with our Azure account.

  1. 在我们的区域管理器中创建了正确的 CNAME DNS 记录(完整且有效).
  2. 设置 Azure WebApp 以响应子域(完整且有效).
  3. 为第二个 Web 应用程序设置一个虚拟目录(完整且有效)

此时,两个 Web 应用程序都正常运行,并且两个子域都指向我们的 Azure 实例.我们现在有以下设置:

At this point, both web applications function correctly and both subdomains are pointing at our Azure instance. We now have the following setup:

  • www.mydomain.com 和 app.mydomain.com 都会启动我部署的根应用程序.
  • 转到 www.mydomain.com/app2 和 app.mydomain.com/app2 会调出我部署到虚拟目录的第二个应用程序

我想要达到的目标:

  • 访问 app.mydomain.com 会在虚拟目录中打开应用程序.
  • 访问 www.mydomain.com 会在 azure 实例的根目录中打开应用程序.

但是,我不知道如何将子域映射到特定的虚拟目录.我尝试将站点 URL 更新为我希望应用程序响应的子域,但是,子域仍然会显示我在 WebApp 部署的根目录中拥有的任何内容.

However, what I cannot figure out is how to map a subdomain to a specific virtual directory. I have tried to update the Site URL to be the subdomain I want the application to respond to, however, the subdomain still brings up whatever I have in the root of the WebApp deployment.

我应该有一些位于站点根目录中的 HttpHandler 并将流量引导到正确的虚拟目录吗?门户中是否有我缺少的设置?以前,我们使用 Web 角色和修改 ServiceDefinition 文件来做到这一点,但 Azure Web 应用程序在发布、与源代码管理集成等方面的工具集似乎更进一步.

Should I have some HttpHandler that sits in the site root and directs traffic to the proper virtual directory? Is there a setting in the portal that I am missing? Previously, we did this with Web Roles and tinkering with the ServiceDefinition file, but the tool sets for the Azure Web Apps in regards to publishing, integration with Source Control, etc seem to be a bit further along.

推荐答案

RuslanY 发布的答案会起作用(对规则稍作修改)但是,在了解更多 Azure 门户和 Web App 配置后,它不是需要在单个 Web 应用程序中托管多个站点(从技术上讲,它的多个 Web 应用程序都共享您定义的资源计划,例如标准级别 0 (S0) 的 2 个实例)*.

The answer posted by RuslanY will work (with some modifications to the rules slightly) however, after understanding more of the Azure portal and Web App configurations, it is not needed to host multiple sites within a single Web App (Its technically multiple web apps all sharing the resource plan you define, such as 2 instances of Standard Level 0 (S0))*.

就今天的 Azure 服务产品而言,以下情况属实.当你创建一个新的 Web 应用程序时,你需要指定应用程序所属的应用程序服务计划".如果您有一个应用服务计划,假设您有 2 个实例的标准,那么您部署到该应用服务计划的任何 Web 应用都与同一服务计划中的其他 Web 应用共享这些资源,这意味着您无需支付额外费用来托管额外的 Web应用如果它在同一个应用服务计划中.我曾假设每个 Web 应用程序都是它自己的一组资源(可以是,但不一定是).鉴于此,为了完成我的需要,我只需为每个子域创建一个 Web 应用程序并将它们全部放入同一个应用程序服务计划中.我现在托管多个站点,而不是为每个站点支付 2 个服务器(我想避免的),并且我不必使用 URL 重写或 HTTP 处理程序.

As of today's Azure service offerings, the following is true. When you create a new Web App, you pecify the "App Service Plan" that the app falls into. If you have an App Service plan, lets say Standard with 2 instances, any Web App you deploy to that App Service plan shares those resources with other web apps in the same service plan, meaning you are not paying additional costs to host the additional web app if it is in the same App Service plan. I had assumed each web app was its own set of resources (it can be, but doesn't have to be). Given this, to accomplish what I need, I simply create a web app for each sub domain and place them all into the same App Service plan. I now am hosting multiple sites, not paying for 2 servers per site (what I wanted to avoid) and I don't have to use URL rewrites or HTTP Handlers.

我希望这篇文章能帮助其他人更好地理解 Azure Web 应用程序的结构.据我所知,当前的在线文档并不能完全清楚地说明这一点.

I hope this write-up helps others understand the structure of the Azure Web Apps a little bit better. The current online documentation, from what I can tell, doesn't make this exactly clear.

这篇关于将子域映射到虚拟目录 Azure WebApps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆