简体   繁体   中英

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. It worked fine when calling the API with specified app service URL(https://<app_service>.azurewebsites.net/).

My virtual path and physical path of the application is like in below image.

虚拟路径和物理路径图像

And this is my NodeJS web API app 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

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.

For eg,

(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

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在此处输入图像描述

  • In the Overview Section of the App service, click on Get Publish Profile在此处输入图像描述

  • In Visual Studio created two NodeJS Web Applications在此处输入图像描述

  • Right click on the first web app and click on publish在此处输入图像描述

  • Browse and select the PUBLISHSETTINGS file downloaded from Azure Web App from portal.在此处输入图像描述

  • Make sure that you are giving the site name as same. Here it is NodeSample .

  • Check and verify the name in both places ( Virtual Applications and directories in Path Mappings and in Publish Settings ) are same.

  • Save and Publish the App.

  • Now select the second Web App and Continue the same steps to publish using Import Profile.

Deployed Web Apps folder structure

在此处输入图像描述

In this case Both the Apps are accessible by using the below URL's Ex:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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