3

I have two different applications which I want to deploy on the same Azure WebApp like this:

webapp.azurewebsites.net/api/ <-- run the Java REST API here
webapp.azurewebsites.net/site/ <- put the Angular2 app here

Problem

Both apps are deployed on the server but currently I'm only able to get the REST API running with a web.config like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Force HTTPS" enabled="true">
          <match url="(.*)" ignoreCase="false"/>
          <conditions>
            <add input="{HTTPS}" pattern="off"/>
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent"/>
        </rule>
      </rules>
    </rewrite>
    <handlers>
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
    </handlers>
    <httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
                  arguments="-jar D:\home\site\wwwroot\webapps\rest-api.war">
    </httpPlatform>
  </system.webServer>
</configuration>

but I'm not able to reach the Angular2 app on the server and I can't find documentation how I would configure the Java application and the Angular2 app at the same time.

I also tried to achieve this with the Virtual applications and directories settings from the Azure dashboard under Application settings - but it didn't work and I can't find a decent documentation of how I would achieve this, or if this is even possible with setting the Virtual applications and directories.

I tried to move the Angular2 site around but was not able to configure the server so that the Angular2 app is accessible while the Java application is running.

Question

Can someone point me to a good documentation on how to achieve this, or describe the deployment process in detail (with regard to the configs, e.g. the Application settings from the Azure Dashboard and the web.config file)?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Tobias Helbich
  • 447
  • 14
  • 32

2 Answers2

5

Per my experience, I think the best way for deploying multiple Apps on Azure WebApps is to set the Virtual applications and directories of Application Settings for your Azure Webapp, please see the figure below.

enter image description here

As reference, please refer to the answer of the SO thread Add virtual directory to existing website on Azure.

Virtual Directories are supported for Azure Websites. See Configuring Azure Websites for what you can do through the Azure Management Portal. From the Azure Portal, click on the Website and go to Configure, then scroll down to virtual applications and directories (the last config section). Just enter your virtual directory and the physical path relative to the site root and click Save.

Community
  • 1
  • 1
Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • Do you know if it is possible to access the `server.xml` and configure Tomcat server? - The problem is that I can not use the embedded Tomcat (from Spring) because website and embedded server are conflicting (but I can access the `server.xml` of the embedded server) and I can not access the Tomcat settings if I use Virtual Directories. – Tobias Helbich Jan 16 '17 at 12:31
  • 1
    @TobiasHelbich You can not access the `server.xml` file to configure Tomcat server installed in `D:\` (except `home` directory) because of no permission. But you can upload a new Tomcat server into `wwwroot` directory via Kudu console, and follow the offical [tutorial](https://learn.microsoft.com/en-us/azure/app-service-web/web-sites-java-custom-upload) to configure & start/stop it. As reference, the SO thread http://stackoverflow.com/questions/27926673/tomcat-8-on-azure-websites is very similar with yours. Hope it helps. – Peter Pan Jan 16 '17 at 16:29
  • As detailed complement, I found this article useful: https://www.c-sharpcorner.com/blogs/host-multiple-application-in-a-single-azure-app-service – Maicon Heck May 05 '20 at 22:28
1

Regarding the second part of your answer, when investigating the subject I found this blog post to be the best explanation of how the Application Settings from the dashboard interact with the Web.config file: https://azure.microsoft.com/en-us/blog/windows-azure-web-sites-how-application-strings-and-connection-strings-work/

In particular -

If the application setting(s) happen to already exist in your web.config file, Windows Azure Web Sites will automatically override them at runtime using the values associated with your website.

So the Application Settings tab in the Azure portal will take precedence over your web.config values.

PartlyCloudy
  • 711
  • 5
  • 14
  • Thanks for the fast answer, this helps understand the interaction between these two. But my problem is still that I can't get my apps running and I can't find any documentation on how to achieve this. – Tobias Helbich Nov 24 '16 at 13:00
  • Are you able to get the desired behavior when you are running locally? i.e. on your localhost? – PartlyCloudy Nov 24 '16 at 13:04
  • The backend has an embedded tomcat and launches from the embedded tomcat (if no tomcat is installed, which is the case for my local dev environment). So I'm not able to reproduce this locally as I'm running both apps at the same time but on different ports and servers. The Azure server is for testing the configuration - I don't care about the local setup (beacuse it is different from Azure), I just want to run on the Azure system and currently this only works for the Java app. – Tobias Helbich Nov 24 '16 at 13:46
  • Also I'm developing with Linux, so I don't think it's possible to create a Tomcat server which I can configure with a `web.config` file which comes from the Microsoft environment - That's also part of the problem, I can't figure out how to configure the `web.config` file for this purpose, and I also don't know if there is a directory structure which I have to adhere to. – Tobias Helbich Nov 24 '16 at 13:53
  • 1
    This link describes something similar to what you are trying to do: https://blogs.msdn.microsoft.com/tomholl/2014/09/21/deploying-multiple-virtual-directories-to-a-single-azure-website/ – PartlyCloudy Nov 24 '16 at 13:53
  • 1
    The author suggest creating two seperate projects, and deploying them one by one. Note that one is the root and the other needs to be deployed after it, and also after the virtual application settings are defined on the Azure application settings. Hope this helps! – PartlyCloudy Nov 24 '16 at 13:55
  • The blog entry says I can achieve this with virtual directories, but I can't see any configuration from the `web.config` and the directory structure on the server would also be helpful - as I don't know if it has an impact on the server configuration or not (I don't use VisualStudio so the pictures won't help me) ... I'll try to move my project around accordingly with the Java app running as a seperate application in a new directory and the Angular2 app running on the `/` and update this question when I have results - again thanks for the fast response :) – Tobias Helbich Nov 24 '16 at 14:07
  • I can't get both apps to run on the same server - either the Angular2 app or the Java app is running, but not both at the same time – Tobias Helbich Nov 24 '16 at 15:23
  • @TobiasHelbich Did you soled the issue back then ? – Rémi Benoit May 08 '20 at 07:55