« Previous Next »

Thread: Simple redirect question

Last post 07-27-2009 11:40 AM by wonyoo. 17 replies.

 

RSS

Page 1 of 2 (18 items) 1 2 Next >

Sort Posts:

  • 07-20-2009, 7:01 AM

    • danyw
    • Not Ranked
    • Joined on 07-20-2009, 10:49 AM
    • Posts 10

    Simple redirect question

    Hi everyone, I am a newbie when it comes to sys-admin stuff. Basically I'd like to filter by host name and redirect appropriately. I'm not sure about the jargon but here's what I'm after:

    Requests that come to host1.domain.com should be redirected to 192.168.1.2, those to host2.domain.com go to 192.168.1.3.

    I've got a couple of rules with regexp of (.*)(host1.domain.com)(.*) redirecting to {R:1}192.168.1.2{R:3}. This works just fine - all the requests get redirected accordingly.

    I have also created a matching rule for host2. This is where the trouble begins. It just happens that 192.168.1.3 is the IIS machine that's handling all this. Going to http://host2.domain.com still redirects it to 192.168.1.2 - not as defined in the rule.

    It is very likely I have missed something terribly obvious. Can someone please help me with this? Any suggestions would be greatly appreciated.

    Cheers,
    Dany.

  • 07-20-2009, 9:44 AM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 10:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: Simple redirect question

    Can you paste your exact rule(s)?

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 07-20-2009, 5:26 PM In reply to

    • danyw
    • Not Ranked
    • Joined on 07-20-2009, 10:49 AM
    • Posts 10

    Re: Simple redirect question

    Unfortunately I did everything through the UI so I can't paste the exact content. I'm not entirely sure where to look for the redirect rules.

  • 07-22-2009, 3:33 AM In reply to

    • danyw
    • Not Ranked
    • Joined on 07-20-2009, 10:49 AM
    • Posts 10

    Re: Simple redirect question

    Found my rewrite rules - they were in c:\inetpub\history where I picked one from a subfolder with the latest timestamp.

    Here it is:

            <rewrite>
                <globalRules>
                    <clear />
                    <rule name="ARR_Code Dogs Limited WF_loadbalance" patternSyntax="Wildcard" stopProcessing="true">
                        <match url="*" />
                        <conditions logicalGrouping="MatchAll" />
                        <action type="Rewrite" url="http://Code Dogs Limited WF/{R:0}" />
                    </rule>
                    <rule name="SavitarMail" stopProcessing="false">
                        <match url="(.*)(savitarmail.sytes.net)(.*)" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{HTTP_HOST}" pattern="savitarmail.sytes.net" />
                        </conditions>
                        <action type="Rewrite" url="{R:1}192.168.1.57{R:3}" />
                    </rule>
                    <rule name="SavitarBernese" stopProcessing="true">
                        <match url="(.*)(savitarbernese.sytes.net)(.*)" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{HTTP_HOST}" pattern="savitarbernese.sytes.net" />
                        </conditions>
                        <action type="Redirect" url="{R:1}192.168.1.58{R:3}" redirectType="Permanent" />
                    </rule>
                </globalRules>
                <rewriteMaps>
                    <rewriteMap name="CodeDogs">
                        <add key="savitarbernese.sytes.net" value="192.168.1.58" />
                        <add key="savitarmail.sytes.net" value="192.168.1.57" />
                    </rewriteMap>
                </rewriteMaps>
            </rewrite>

    I'm not sure why that load balancing rule is there - any suggestions would be greatly appreciated.

    Thanks,
    Dany.

  • 07-23-2009, 2:19 AM In reply to

    • wonyoo
    • Top 50 Contributor
    • Joined on 12-15-2007, 1:46 PM
    • Posts 140

    Re: Simple redirect question

    I see a few things.

    1) The URL rewrite rules are process from top to bottom.  So in your case, all incoming requests are being forwarded to "Code Dogs Limited WF" - and the following 2 rules are not being exercised at all.   Question - are you planning on using the "Code Dogs Limited WF".  I don't think you do.  If you are not planning on using it, then please remove the rule from config.

    2) In order to use ARR as a proxy (which is what you are trying to do), you have to enable the proxy feature.  Depending on whether you have ARRv1, ARRv2 Beta1 or ARRv2 Beta2, the location of this checkbox is slightly different.  Please let me know which one you are using. 

    3) As for your last rule, you are using an action type of redirect - do you mean to do that?  Or do you want that to be proxied through ARR as well?

  • 07-23-2009, 6:51 AM In reply to

    • danyw
    • Not Ranked
    • Joined on 07-20-2009, 10:49 AM
    • Posts 10

    Re: Simple redirect question

    Thanks for the quick response wonyoo - I will give this a try soon as I am not anywhere near the machine at the moment. I only downloaded the ARR module last month so I assume it's ARRv1.

    I'm not entirely sure which one I need to achieve this, redirect or rewrite. I simply want to requests to go to the appropriate machines depending on the hostname in the request.

    Thanks,
    Dany.

  • 07-23-2009, 11:00 AM In reply to

    • wonyoo
    • Top 50 Contributor
    • Joined on 12-15-2007, 1:46 PM
    • Posts 140

    Re: Simple redirect question

    Dany

    Yes, try that out and let me know if it works.  Sounds like you probably have v1.  What that means is when you click on the server node of the tree view in the navigation pane, you will see an "Application Request Routing" icon.  Double click on that and on the top of the page, there will be a check-box for enabling (what we call, "sever level") proxy.  You will want to do that.

    As for rewrite vs. redirect - if you want to proxy the request, then you want rewrite (ie. the URL on the browse remains that of proxy).  If you want to send 302 back to your client, then you want redirect.  The difference, of course, is that in proxy case, your client thinks that they are connecting to the proxy.  In redirect, the client is redirected (ie. the URL on the browser will change).  Sounds like you want rewrite.

  • 07-24-2009, 5:21 AM In reply to

    • danyw
    • Not Ranked
    • Joined on 07-20-2009, 10:49 AM
    • Posts 10

    Re: Simple redirect question

    Ok, I think I tried what you suggested correctly - unfortunately there are a couple of points I am not sure about:

    1. On the Server Level proxy page do I accept all the default values for the rest of the page?

    2. Do I need to tick "Use URL Rewrite to inspect incoming requests"? If so, what value do I use for Reverse proxy?

    3. I want all traffic to a particular domain (savitarbernese.sytes.net) to be forwarded to 192.168.1.58, but everything else to stay on the same server. Do I need a rewrite rule as well as enabling the proxy?

    Sorry about all this - I'm not a system admin and seriously lack understanding of the basic proxy principles. If I tick "Use URL Rewrite..." it creates an entry that stops processing subsequent rules. Not entirely sure that's what's supposed to happen. I think the whole UI is confusing me, on top of my lack of understanding.

    Can you please help me a bit further on this one?

  • 07-24-2009, 12:45 PM In reply to

    • wonyoo
    • Top 50 Contributor
    • Joined on 12-15-2007, 1:46 PM
    • Posts 140

    Re: Simple redirect question

    No problems.

    I think I understood you fully, but I wanted to repeat it to ensure that I do.

    • You are using ARR in a hybrid mode.  Meaning, it is both a proxy (for savitarbernese.sytes.net) and for all others, it is a content server.
    • For requests with hostname savitarbernese.sytes.net, you want them to be forwarded to 192.168.1.58.

    Is that it?

    Assuming that above is what you want, here are the couple of steps that you will need to take.

    Before you start though, make sure that you don't have any server farms created and/or any URL rewrite rules have been written.  If so, please remove them.  I am assuming that you have a clean start.

    1) Let's enable proxy.  For that, on the page that you have already located, check "Enable proxy" checkbox.  Accept all the default values, except:

    - select "Use URL Rewrite to inspect incoming requests"

    - in "Reserver proxy:", enter 192.168.1.58

    Doing just the above has now setup the ARR.  However, ALL requests are being forwarded to 192.168.1.58.

    2) So in order to only forward the requests with hostname savitarbernese.sytes.net, let's further modify the URL rewrite rule.  Select the server node in the navigation tree view.  Select URL rewrite icon.  Note that there is one rule that has been created (from step 1 above).  It should be named something like "ARR_server_proxy".  Select the rule and click "Edit".

    Once you are in the "editing" mode, sleect "Add Conditions", the click "Add...".   In "Add Condition" dialog, enter {HTTP_HOST}, Matches the pattern savitarbernese.sytes.net.  Click on OK to save.  The "Add Condition" dialog is now closed and you are back to Edit Rule page.  Click on Apply on the right hand side to save the changes.

    Basically what you have done in step 2 is to add a contion to the rule so that the rule is applied only when the condition is true (in which case the host header is "savitarbernese.sytes.net").

     

    That should do the trick.  Let me know if you have further questions.

  • 07-24-2009, 5:04 PM In reply to

    • danyw
    • Not Ranked
    • Joined on 07-20-2009, 10:49 AM
    • Posts 10

    Re: Simple redirect question

    Wow - that's a very thorough set of instructions. Thanks again.

    I have actually tried that before and it half worked. Requests to savitarbernese.sytes.net are forwarded to 192.168.1.58. Unfortunately so is everything else! It doesn't seem to filter only those with the matching hostname...

    Here's the latest incarnation of the rules:

            <rewrite>
                <globalRules>
                    <clear />
                    <rule name="ARR_server_proxy" patternSyntax="Wildcard" stopProcessing="true">
                        <match url="*" />
                        <action type="Rewrite" url="http://192.168.1.58/{R:0}" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="savitarbernese.sytes.net" />
                        </conditions>
                    </rule>
                </globalRules>
                <rewriteMaps>
                </rewriteMaps>
            </rewrite>
            <proxy enabled="true" />

  • 07-24-2009, 6:19 PM In reply to

    • wonyoo
    • Top 50 Contributor
    • Joined on 12-15-2007, 1:46 PM
    • Posts 140

    Re: Simple redirect question

    Have you tried it with the new rule?   It didn't work the first time b/c you had other rules in URL rewrite (the rules are processed from top to bottom):

                     <rule name="ARR_Code Dogs Limited WF_loadbalance" patternSyntax="Wildcard" stopProcessing="true">
                        <match url="*" />
                        <conditions logicalGrouping="MatchAll" />
                        <action type="Rewrite" url="http://Code Dogs Limited WF/{R:0}" />
                    </rule>
                    <rule name="SavitarMail" stopProcessing="false">
                        <match url="(.*)(savitarmail.sytes.net)(.*)" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{HTTP_HOST}" pattern="savitarmail.sytes.net" />
                        </conditions>
                        <action type="Rewrite" url="{R:1}192.168.1.57{R:3}" />
                    </rule>

    Another way to troubleshoot this is to enable Failed Request Tracing and see how the URL rules are being evaluated. 

    I basically have the same setup and it seems to work as expected:

                <globalRules>
                    <rule name="ARR_server_proxy" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
                        <match url="*" />
                        <action type="Rewrite" url="http://wonyoo-w2k8/{R:0}" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="arr1" />
                        </conditions>
                    </rule>
                </globalRules>

    (in my case, if users are connecting to the server using "arr1" as the domain, then they get routed to wonyoo-w2k8 server.

  • 07-24-2009, 6:54 PM In reply to

    • danyw
    • Not Ranked
    • Joined on 07-20-2009, 10:49 AM
    • Posts 10

    Re: Simple redirect question

    Yup, I tried it with the new rule as listed in my latest post. It actually works, ie. savitarbernese.sytes.net is indeed forwarded to 192.168.1.58. Unfortunately so do everything else! It doesn't just forward requests with savitarbernese.sytes.net.

    How do I stop requests with other host headers from being forwarded? I thought the condition to match the appropriate http_host is supposed to only forward those that match the condition?

  • 07-24-2009, 7:06 PM In reply to

    • wonyoo
    • Top 50 Contributor
    • Joined on 12-15-2007, 1:46 PM
    • Posts 140

    Re: Simple redirect question

    Your understanding is absolutely right.  So I susect that the URL rewrite rules are somehow not being processed properly.  In order to step through this, you can enable Failed Tracing Rule.  The steps for this can be found at http://learn.iis.net/page.aspx/467/using-failed-request-tracing-to-trace-rewrite-rules/

    This will allow you to step through the rules as the request is going through the pipeline.  So you can identify how the rules are being processed for other host header.  Given that everything is being forwarded, I would have to guess that somehow the rules are not being matched correctly.

    Once you enable Failed Tracing Rules and collect some data, let me know if you have trouble reading through the data.  I can help you with that.

  • 07-24-2009, 8:47 PM In reply to

    • danyw
    • Not Ranked
    • Joined on 07-20-2009, 10:49 AM
    • Posts 10

    Re: Simple redirect question

    I have turned on the Failed Request Tracing but the log folder is empty. I have a suspicion it's not actually "failing" as such, just not doing quite what it's supposed to be.

    Admittedly I didn't follow the instructions exactly like that article said. I figured all I need to do is make a request to savitarbernese.sytes.net and savitarmail.sytes.net to test it. Both went to 192.168.1.58 - nothing stayed within 192.168.1.57.

    I have a feeling I have missed something obvious - just can't think of what...

  • 07-24-2009, 9:16 PM In reply to

    • wonyoo
    • Top 50 Contributor
    • Joined on 12-15-2007, 1:46 PM
    • Posts 140

    Re: Simple redirect question

    Depending on the FREB rule, you may not get any log.  Are you collecting logs for response 200-999?  The term "failed request" may seem confusing.  The request does not have to fail, per se - it generates the traces based on the rule/criteria.  So if you configure it to collect anything between 200-999,  you should get the log.   Based on the log, we can figure out what's going on with the URL rewrite rules.

Page 1 of 2 (18 items) 1 2 Next >