IIS Reverse Proxy for the Play Framework - iis

I have a play application that I would like to set up on an IIS server. I want to set up an reverse proxy. In Apache I would do something like this:
ProxyPass /myapp localhost:9000/myapp
ProxyPassReverse /myapp localhost:9000/myapp
How can I accomplish something like this?

<rule name="IIS reverse proxy for play framework" enabled="true" stopProcessing="true">
<match url="^(appName.*)" />
<action type="Rewrite" url="http://localhost:9000/{R:1}" />
<conditions>
<add input="{HTTP_HOST}" pattern=".+" />
</conditions>
</rule>

Related

ARR proxy rule issue

I need to create proxy rewrite in IIS using ARR
So:
I have 2 servers:
https://server1.com
https://server2.com
Now in each of them i have virtual folder
https://server1.com
FilesFolder
https://server2.com
FilesFolder
I saved files in server2
like:
https://server2.com
FilesFolder
users-profile
test.png
Now i need when i open chrome
https://server1.com/FilesFoler/users-profile/test.png
I want that this request go to
https://server2.com/FilesFoler/users-profile/test.png
Now I did proxy rule for Server 1:
Test 1:
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="https://server2/{C:0}" />
<conditions>
<add input="{URL}" pattern="/users-profile/.*" />
</conditions>
</rule>
</rules>
This rule not work if i open url like:
https://server1.com/FilesFoler/users-profile/test.png
But work wjen I open:
https://server1.com/FilesFoler/FilesFoler/users-profile/test.png
Then i try another rule;
Test 2
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="https://server2/FilesFolder/{C:0}" />
<conditions>
<add input="{URL}" pattern="/users-profile/.*" />
</conditions>
</rule>
</rules>
But when I open https://server1.com/FilesFoler/users-profile/test.png
This still not work.....
What wrong here?
In this case, if your request is https://server1.com/FilesFoler/users-profile/test.png.
When IIS handle the condition pattern <add input="{URL}" pattern="/users-profile/.*" />.
Then your {C:0} should be users-profile/test.png.
So the request will be rewritten to
https://server2/users-profile/test.png
instead of
https://server2.com/FilesFoler/users-profile/test.png.
So please replace [C:0} to {R:1} or {R:0}
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="https://server2/{R:0}" />
<conditions>
<add input="{URL}" pattern="/users-profile/.*" />
</conditions>
</rule>
Since you are not using ssl-offloading for server2. Please ensure server2 is using a trusted certificate, otherwise, SSL handshake between ARR and Server2 may fail.
If you get 404 error, please remember to enable Proxy setting in IIS manager->server node->application request routing cache-> Enable proxy.

IIS 10 / ARR 3 / Websocket /

I have an IIS 10 with ARR 3.0 and websockets
If I'm using directly iis, my websockets works great.
The websocket's address is like ws://IP_SERVER:PORT/ws/XXXX
If I'm using the same iis (and same site with a rewrite url rule) as reverse proxy, my websocket connects and disconnects forever.
The websocket's address is like ws://DOMAIN:PORT/ws/XXXX
The Url Rewrite configuration is:
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="{C:1}://localhost:1880/{R:1}" />
<conditions>
<add input="{CACHE_URL}" pattern="^(.+)://" />
</conditions>
</rule>
</rules>
</rewrite>
Can you help me please ?
Thanks

Rewrite URL for path to domain in Azure App Service using Virtual Directory

I have set up an Azure App Service to use Virtual Directories.
The path my-app.azurewebsites.net/api is working correctly with the site wwwroot/api.
I have a CNAME record for api.mydomain.com to my-app.azurewebsites.net which works just fine as well. I can successfully call api.mydomain.com/api.
However I'd like to use a subdomain instead of the path, rewriting api.mydomain.com to api.mydomain.com/api
I've added a web.config file in my wwwroot directory which looks like following now
wwwroot/
- api/
- web.config
web.config:
<rewrite>
<rules>
<rule name="My redirection">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^api.mydomain.com$" />
</conditions>
<action type="Redirect" url="https://api.mydomain.com/api/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
After a restart, the App Service is not responsive and does not serve requests anymore. Is there a better way to achieve this or do I need to modify my rewrite?
After a few attempts I figured the mistake. Redirect has to be changed into Rewrite.
<rewrite>
<rules>
<rule name="My redirection">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="api.mydomain.com$" />
</conditions>
<action type="Rewrite" url="api/{R:1}" />
</rule>
</rules>
</rewrite>

IIS: Redirect subdomain to specific url

In IIS 8, I want to redirect the url http://test.example.com to http://www.example.com/abc/123
I try this, but not work.
<rule name="test" stopProcessing="true">
<match url="^test.example.com$" />
<action type="Redirect" url="http://www.example.com/abc/123" />
</rule>
you could add the pattern like this
<rule name="RedirectDomain" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="(.*)test.example.com />
</conditions>
<action type="Redirect" url="http://www.example.com/abc/123" redirectType="Permanent" />
</rule>
In the IIS GUI on the given side you should be able to choose 'HTTP Redirect' from there you can type in a url to redirect the site to.
I don't know if this approach is the recommended (It is normally used to redirect HTTP request on a given site to use HTTPS), but it will solve your problem.

Simple IIS URL Rewrite

Simple question. I need to redirect all http 80 and https 443 requests on a specific subdomain URL to an alternative SSL port https 444.
Example: http://sub.corp.com --> https://sub.corp.com:444
Example: https://sub.corp.com --> https://sub.corp.com:444
I only wish to use IIS 7.5 URL Rewrite module.
Thanks.
The following URL rewrite rule should do what you want:
<rewrite>
<rules>
<rule name="Redirect to port 444" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="^ON$" negate="true" />
<add input="{SERVER_PORT}" pattern="^444$" negate="true" />
</conditions>
<action type="Redirect" url="https://sub.corp.com:444/{R:0}" />
</rule>
</rules>
</rewrite>
It redirects to https://sub.corp.com:444 whenever HTTPS is not ON or when the port number is not 444. The site should have bindings to port 80 (with HTTP), 443 (with HTTPS for standards SSL) en 444 (with HTTPS) for this to work.
Marco's solutions works fine, in case somebody is wondering how to apply this in IIS.
you add this to the web.config file. If you create a Virtual Directory in IIS the selected physical folder will have a web.config created.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to port 50443" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="^ON$" negate="true" />
<add input="{SERVER_PORT}" pattern="^50443$" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}:50443/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Resources