IIS ARR Loadbalancer always hits top URL rewrite rule - iis

I have a public IP mapped to my router and 3 servers in LAN connected to the Router. 1st Server is ARR LoadBalancer and 2nd and 3rd Servers are hosted with a Website on port 80.
Doing port forwarding on router for port 80 to ARR LoadBalance Server.
I have selected Load Balance Algorithm as: Weighted Round Robin, and Load distribution as Even distribution on both the Server Farms.
Always the top URL Rewrite is hit, the load is not distributed in RoundRobin fashion.
I have written URL Rewrite as below:
gc80 is ServerFarm for Server1.
gc2_80 is ServerFarm for Server2.
<rewrite>
<globalRules>
<clear />
<rule name="PublicIP_to_Server1_80" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="PublicIPHere*" />
</conditions>
<action type="Rewrite" url="http://gc80/{R:0}" />
</rule>
<rule name="PublicIP_to_Server2_80" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="PublicIPHere*" />
</conditions>
<action type="Rewrite" url="http://gc2_80/{R:0}" />
</rule>
</globalRules>
</rewrite>
<proxy enabled="true" />
Please let me know if i am missing anything for LoadBalancing?

Related

IIS 10 URL Rewrite http traffic to https redirect not working

IIS 10 server behind an AWS application load balancer will not redirect traffic for domain without www when client requests http rather than https. The rule to redirect traffic when www is specified works fine, but 404 is returned if you try the same url without www.
So:
Enter "http://dname.com/blog" = 404
Enter "http://www.dname.com/blog" = redirect to "https://www.dname.com/blog"
<rule name="Force HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_X_Forwarded_Proto}" pattern="^https$" negate="true" />
<add input="{HTTP_HOST}" pattern="^dname\.com$" />
</conditions>
<action type="Rewrite" url="https://www.dname.com{REQUEST_URI}" />
</rule>
<rule name="Force WWW HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_X_Forwarded_Proto}" pattern="^https$" negate="true" />
<add input="{HTTP_HOST}" pattern="^www\.dname\.com$" />
</conditions>
<action type="Redirect" url="https://www.dname.com{REQUEST_URI}" />
</rule>
Nothing worked for me even after going through the answers provided on different forums.
After 2 days of banging my head in this here's what I found which solved the issue :
Bindings : Port 80 must be enabled (This can be added in bindings section in IIS).
SSL settings : Required SSL must be unchecked.
Add Rule :
<rewrite>
<rules>
<rule name="http to https redirection" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"
appendQueryString="false" />
</rule>
</rules>
</rewrite>
Verify web config as it should reflect the rule added in IIS.
I don't know why the previously posted rules wouldn't work, but I was able to create a refined rule that is working:
<rule name="Force HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_X_Forwarded_Proto}" pattern="^https$" negate="true" />
<add input="{HTTP_HOST}" pattern="^(www\.)?dname\.com$" />
</conditions>
<action type="Redirect" url="https://www.dname.com{REQUEST_URI}" />
</rule>
The above rule combines the two rules instead of looking for the domain without the www and then with the www in a separate rule. The regex (www\.) tells the rule to look for "www." and the question mark tells it that it may or may not be there, so that includes the domain with and without the www.
There is a very very important step that should take care, before setup a redirect configure.
in web Sites project --> Actions(in the right) --> Bindings , the content will like below:
Binding Content
You take carefully the yellow color part, the yellow part is your original web IP address. This original IP address must exist in "Site Bindings", without the yellow part the URL redirect will not working anymore.
The following config is my current IIS URL redirect setting:
<rewrite>
<globalRules>
<rule name="Http redirect to Https" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="localhost:8080" /> <-- the Red one should match above Site Bindings original IP address
</conditions>
<action type="Redirect" url="https://Your-Host-Name/{R:1}" redirectType="SeeOther" />
</rule>
</globalRules>
</rewrite>

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 http to https rewrite rule and exclude IP address

I wrote a http to https rewrite rule in IIS.
I want to exclude a http://XXX.XX.XXX.XX (one single IP address) from this.
Then I want to write another rule that rewrites those http://XXX.XX.XXX.XX and https://XXX.XX.XXX.XX to https://www.foo.com (my domain which I have ssl certificate for).
Here both rules:
<rule name="http to https redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{REQUEST_URI}" pattern="^/XXX.XX.XXX.XX$" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>
<rule name="Redirect to my site">
<match url="XXX.XXX.XXX.XX" />
<conditions>
<add input="{QUERY_STRING}" pattern="XXX.XXX.XXX.XX" />
</conditions>
<action type="Rewrite" url="https:www.foo.com" />
</rule>
It does not work with the excluded pattern and I wonder if the second rule applies at all. Any advise is wellcome.

Redirect HTTPS to HTTP IIS 10

I have IIS 10 running locally in my development environment. I am trying to test an SSO solution with a test ADFS instance. However, ADFS only allows for a secured endpoint to redirect to. I need to setup my local environment to change any requests that come in as https to http. Here is the configuration I have tried:
<rule name="Force Http" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="on" />
</conditions>
<action type="Rewrite" url="http://{HTTP_HOST}/{REQUEST_URI}" />
</rule>
The user is not being redirected and I am just getting a 404. I have tried with and without an https binding on the default website that I have the site sitting under.
Here is the solution that finally worked for me:
<rule name="No-https" enabled="true" stopProcessing="true">
<match url=".*" negate="false" />
<action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" />
<conditions trackAllCaptures="false">
<add input="{SERVER_PORT_SECURE}" pattern="^1$" />
</conditions>
</rule>

HTTPS redirect rewrite rule not working in IIS

Our website, hosted in IIS 10, is covered by a valid SSL certificate. It works fine under the https version of the address.
To catch the http traffic and redirect it, I added a rewrite rule in the web.config, as follows:
<rule name="Redirect to http" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="(.*)" negate="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
I'd used this before and expected it to work fine. However on this server, it doesn't seem to function. Trying to reach the site on http yields an ERR_EMPTY_RESPONSE error.
I searched through a bunch of tutorials, most of which seemed to support the rewrite I'd got. However, I did find and try this slightly different version
<rule name="Redirect to http" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{SERVER_PORT_SECURE}" pattern="^0$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
But that didn't work either with the same ERR_EMPTY_RESPONSE to http.
The site is bound to https via the host name on 443, and has a binding on port 80 with an empty host name.
Other rewrite rules such as an IP-based access whitelist seem to be working fine, so it's unlikely to be an issue with the rewrite module.
At a loss as to what I'm doing wrong?

Resources