简体   繁体   English

是否可以在单个 azure 应用服务中部署多个 Nodejs Web API 应用?

[英]Is there possible to deploy multiple Nodejs Web API App in single azure app service?

My requirement is simple.我的要求很简单。

I already have an one azure app service (https://<app_service>.azurewebsites.net/) and I hosted a NodeJs Web API app under that above mentioned app service.我已经有一个 azure 应用服务 (https://<app_service>.azurewebsites.net/) 并且我在上述应用服务下托管了一个 NodeJs Web API。 It worked fine when calling the API with specified app service URL(https://<app_service>.azurewebsites.net/).使用指定的应用服务 URL (https://<app_service>.azurewebsites.net/) 调用 API 时,它工作正常。

My virtual path and physical path of the application is like in below image.我的应用程序的虚拟路径和物理路径如下图所示。

虚拟路径和物理路径图像

And this is my NodeJS web API app web.config这是我的 NodeJS web API 应用程序 web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
  <webSocket enabled="false" />
  
  <handlers>
    <add name="iisnode" path="index.js" verb="*" modules="iisnode"/>
  </handlers>
  <rewrite>
    <rules>
      <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
        <match url="^index.js\/debug[\/]?" />
      </rule>

      <rule name="StaticContent">
        <action type="Rewrite" url="public{REQUEST_URI}"/>
      </rule>

      <rule name="DynamicContent">
        <conditions>
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
        </conditions>
        <action type="Rewrite" url="index.js"/>
      </rule>
    </rules>
  </rewrite>

  <security>
    <requestFiltering>
      <hiddenSegments>
        <remove segment="bin"/>
      </hiddenSegments>
    </requestFiltering>
  </security>

  <httpErrors existingResponse="PassThrough" />
</system.webServer>

And this is my NodeJS web API app index.js这是我的 NodeJS web API app index.js

var express = require("express");
var app = express();

app.get("/", function(req, res) {
  res.send("Call from Node API!!!");
});

var port = process.env.PORT || 1660;

var server = app.listen(port, function () {
  console.log("Listening on port %s...", server.address().port);
});

Now, I want this same NodeJS Web API application with another virtual path with same azure app service.现在,我想要这个相同的 NodeJS Web API 应用程序和另一个具有相同 azure 应用程序服务的虚拟路径。

For eg,例如,

(https://<app_service>.azurewebsites.net/nodeapi) (https://<app_service>.azurewebsites.net/nodeapi)

新的虚拟路径

Is this possible to achieve?这有可能实现吗? If so, could you please tell me how to achieve this.如果是这样,你能告诉我如何实现这一目标。

Thanks in advance!提前致谢!

It is possible to deploy Multiple Web Apps under same App service by using Import Profile and Adding Virtual Directories in Azure Portal通过在 Azure 门户中使用Import Profile和添加虚拟目录,可以在同一应用服务下部署多个 Web 应用

Check the below workaround检查以下解决方法

  • Created an App service with Runtime stack Node.使用运行时堆栈节点创建了一个应用服务。

  • In the newly created app service add the virtual applications under Configuration => Path Mappings Section在新创建的应用服务中,在Configuration => Path Mappings部分下添加虚拟应用程序在此处输入图像描述

  • In the Overview Section of the App service, click on Get Publish Profile在应用服务的概览部分,单击Get Publish Profile在此处输入图像描述

  • In Visual Studio created two NodeJS Web Applications在 Visual Studio 中创建了两个NodeJS Web Applications在此处输入图像描述

  • Right click on the first web app and click on publish右键单击第一个 web 应用程序,然后单击发布在此处输入图像描述

  • Browse and select the PUBLISHSETTINGS file downloaded from Azure Web App from portal.浏览并 select 从门户网站Azure Web App下载的 PUBLISHSETTINGS 文件。在此处输入图像描述

  • Make sure that you are giving the site name as same.确保您提供的站点名称相同。 Here it is NodeSample .这是NodeSample

  • Check and verify the name in both places ( Virtual Applications and directories in Path Mappings and in Publish Settings ) are same.检查并验证两个地方的名称(路径映射和Publish Settings中的虚拟应用程序和目录)是否相同。

  • Save and Publish the App. SavePublish应用程序。

  • Now select the second Web App and Continue the same steps to publish using Import Profile.现在 select 第二个 Web 应用程序并继续使用导入配置文件发布相同的步骤。

Deployed Web Apps folder structure部署 Web Apps 文件夹结构

在此处输入图像描述

In this case Both the Apps are accessible by using the below URL's Ex:在这种情况下,这两个应用程序都可以使用以下 URL 的Ex 访问:

https://nodesample.azurewebsites.net/NodejsSample1
https://nodesample.azurewebsites.net/NodejsSample2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM