1

I came to know there are multiple ways to set up the IIS server as a proxy but not sure which option is suitable for my case.

I want to use my IIS server as a proxy server to access my application running on Tomcat. The reason is, my IIS is running on a secure port. This port is already opened and I want to utilize it.

I tried reverse proxy in IIS. It routes the traffic but I noticed two issues.

  1. It changes the address on the address bar (I see my Tomcat application address + port in the address bar) although I set the option to Rewrite while setting up the proxy.
  2. It does not work well if I do not append the forward slash at the end of my URL.

My IIS server has some other applications hosted as well. I do not want to disturb other applications. So I created an empty web application (e.g. https://myserver/myapp/) and set up a reverse proxy on it.

This is my reverse proxy rule;

enter image description here enter image description here

Please correct me if this is the right approach. If yes am I missing anything?

Edit 1

I have tried HttpPlatformHandler. It is giving 502.3 Bad Gateway. Here are my configurations in web.config file.

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
  <system.webServer>
    <handlers>
      <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
    </handlers>
    <httpPlatform processPath="C:\Program Files\Apache Software Foundation\Tomcat 9.0_x\bin\startup.bat" arguments="" stdoutLogEnabled="true" stdoutLogFile="c:\dev\javasites\log.txt">
      <environmentVariables>
        <environmentVariable name="JRE_HOME" value="C:\Program Files\AdoptOpenJDK\jre-8.0.232.09-hotspot" />
        <environmentVariable name="CATALINA_HOME" value="C:\Program Files\Apache Software Foundation\Tomcat 9.0_x" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
</configuration>

--- log.txt -----

 Using CATALINA_BASE:   "C:\Program Files\Apache Software Foundation\Tomcat 9.0_x"
Using CATALINA_HOME:   "C:\Program Files\Apache Software Foundation\Tomcat 9.0_x"
Using CATALINA_TMPDIR: "C:\Program Files\Apache Software Foundation\Tomcat 9.0_x\temp"
Using JRE_HOME:        "C:\Program Files\AdoptOpenJDK\jre-8.0.232.09-hotspot"
Using CLASSPATH:       "C:\Program Files\Apache Software Foundation\Tomcat 9.0_x\bin\bootstrap.jar;C:\Program Files\Apache Software Foundation\Tomcat 9.0_x\bin\tomcat-juli.jar"
Abdul Waheed
  • 383
  • 1
  • 4
  • 20
  • 1) I commented in that thread years ago. HttpPlatformHandler should be your primary option. 2) When you use "Rewrite" in ARR, the address bar shouldn't change, unless your Java web app does not even work with reverse proxying and performs redirection on its own. You have to trace down the source of redirection so as to move on. – Lex Li Nov 28 '19 at 14:11
  • Thanks, I tried HttpPlatformHandler; it is giving 502.3 bad gateway error. I have added my web.config in my first edit. Any idea? – Abdul Waheed Nov 28 '19 at 16:03
  • please check whether the common feature for IIS in turn windows features on or off has been installed. I suggest you try the steps to configure the HTTP platform handler following this [link](https://azure.microsoft.com/en-us/blog/announcing-the-release-of-the-httpplatformhandler-module-for-iis-8/).install HTTP platform handler via web platform installer and test with the sample website, sometimes, the installation via MSI is not verified. – Jalpa Panchal Nov 29 '19 at 06:32
  • IIS ARR (Application Request Routing) to redirect to Tomcat refer this [link1](https://blogs.sap.com/2014/11/05/how-to-configure-iis-arr-application-request-routing-to-redirect-to-tomcat/) – Jalpa Panchal Nov 29 '19 at 06:32
  • @JalpaPanchal I enabled the HTTP feature in IIS features list and installed the HTTP platform handler via web platform, nothing much changed after. However I noticed the handler was not able to create the log directory, I created it manually and see logging of a variable in log.txt file. On the browser, it always goes on loading. Please see the logs are under Edit 1. – Abdul Waheed Nov 29 '19 at 10:29
  • For IIS ARR, it worked but I notice it switch to HTTP and change the URL after redirecting. I see my Tomcat application URL in address bar e.g. http://myserver:8080/myapp – Abdul Waheed Nov 29 '19 at 11:22

1 Answers1

2

I have managed to fix this issue.

The root cause was my Java application. It was somehow replacing the hostname and port. I provided the proxy settings in my HTTP connector settings in server.xml under the Tomcat>Conf folder. So my HTTP connector update the proxyName and port after my application change the url.

 proxyName="myserver"
           proxyPort="myport"
           scheme="https"

See more details under Proxy Support section.

Abdul Waheed
  • 383
  • 1
  • 4
  • 20