# Virtual server with two different web servers

**URL:** <https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260>\
**Category:** Technical Forums\
**Tags:** big-ip-access-policy-manager-apm, security, ltm, application-delivery\
**Created:** [January 15, 2015, 8:48pm UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260 "2015-01-15T20:48:07Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keith\_Fox\_15580](https://avatars.discourse-cdn.com/v4/letter/k/5f9b8f/32.png) [@Keith\_Fox\_15580](https://community.f5.com/u/Keith_Fox_15580)\
**Post date:** [January 15, 2015, 8:48pm UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/1 "2015-01-15T20:48:07Z")

</div>

I have a virtual server that needs to have two different web servers behind it, so that I can present it via the internet. The reasoning for this is server1, redirects to server2 two for authentication, then after authenticating it redirects back to server1, where it stays for all other functions.

I tried using this irule below, but it does not seem to be working. It is forwarded to the other site, but using the internal name of the site, so it times out as it is not available under that name on the internet.

when HTTP\_REQUEST { switch [string tolower [HTTP::host]] { “[server1.domain.com](http://server1.domain.com)” { pool server1\_test\_pool } “[server2.domain.com](http://server2.domain.com)” { pool server2\_test2\_pool } } }

---

<div class="post-metadata">

**Author:** ![Michael\_Jenkins](https://avatars.discourse-cdn.com/v4/letter/m/43a26b/32.png) [@Michael\_Jenkins](https://community.f5.com/u/Michael_Jenkins)\
**Post date:** [January 15, 2015, 10:52pm UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/2 "2015-01-15T22:52:33Z")

</div>

Is your web server expecting soemthing different than [server2.domain.com](http://server2.domain.com)? Is it expecting [server1.domain.com](http://server1.domain.com) as well to access the website?

---

<div class="post-metadata">

**Author:** ![Keith\_Fox\_15580](https://avatars.discourse-cdn.com/v4/letter/k/5f9b8f/32.png) [@Keith\_Fox\_15580](https://community.f5.com/u/Keith_Fox_15580)\
**Post date:** [January 16, 2015, 6:12am UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/3 "2015-01-16T06:12:42Z")

</div>

No, it is not. The process is as follows: Server1 receives initial web request, upon this request it forwards to server2 for authentication, then forwards back to Server1, where the rest of the web traffic will be taken place.

I am stuck at where server1 directs to server2, it is using an internal address, which externally is not resolvable, so I get a server cannot be found error. I need all this address translation to happen behind the virtual server, not a redirect to a server2 which is not accessible via the internet with it’s name.

---

<div class="post-metadata">

**Author:** ![What\_Lies\_Bene1](https://avatars.discourse-cdn.com/v4/letter/w/59ef9b/32.png) [@What\_Lies\_Bene1](https://community.f5.com/u/What_Lies_Bene1)\
**Post date:** [January 16, 2015, 7:53am UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/4 "2015-01-16T07:53:16Z")

</div>

Why not just use two Virtual Servers. Change DNS so server1. and server2. resolve to different IPs (and thus different Virtual Servers) and configure your F5 as appropriate.

If you want to stick to the iRule I would suggest you also turn on OneConnect. You could use a stream profile to rewrite the internal name as required but I’d say it would be better to fix this at the server.

---

<div class="post-metadata">

**Author:** ![Keith\_Fox\_15580](https://avatars.discourse-cdn.com/v4/letter/k/5f9b8f/32.png) [@Keith\_Fox\_15580](https://community.f5.com/u/Keith_Fox_15580)\
**Post date:** [January 16, 2015, 2:47pm UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/5 "2015-01-16T14:47:51Z")

</div>

I wish using two virtual servers would work, but they have hard set in the web program to redirect to the internal name, so it’s not possible, and the internal domain is not something we own, so not route-able outsie of our LAN.

---

<div class="post-metadata">

**Author:** ![What\_Lies\_Bene1](https://avatars.discourse-cdn.com/v4/letter/w/59ef9b/32.png) [@What\_Lies\_Bene1](https://community.f5.com/u/What_Lies_Bene1)\
**Post date:** [January 16, 2015, 2:57pm UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/6 "2015-01-16T14:57:06Z")

</div>

Understood, not unusual. So, you’ll need a Stream Profile and iRule to rewrite the responses and replace any instance of the internal name with a suitable external one. See here for a simple example: [https://devcentral.f5.com/wiki/iRules.STREAM\_\_enable.ashx](https://devcentral.f5.com/wiki/iRules.STREAM__enable.ashx) and further details.

---

<div class="post-metadata">

**Author:** ![Keith\_Fox\_15580](https://avatars.discourse-cdn.com/v4/letter/k/5f9b8f/32.png) [@Keith\_Fox\_15580](https://community.f5.com/u/Keith_Fox_15580)\
**Post date:** [January 16, 2015, 3:10pm UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/7 "2015-01-16T15:10:54Z")

</div>

Ok, I am new to the F5, so you are saying I will still need to external Virtual servers to perform this operation, or just one, with the stream?

---

<div class="post-metadata">

**Author:** ![What\_Lies\_Bene1](https://avatars.discourse-cdn.com/v4/letter/w/59ef9b/32.png) [@What\_Lies\_Bene1](https://community.f5.com/u/What_Lies_Bene1)\
**Post date:** [January 16, 2015, 3:16pm UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/8 "2015-01-16T15:16:12Z")

</div>

It’s your choice. You can stick with 1, have DNS provide the same IP for both domain names and use the iRule to select the correct server. Or have a second VS, second pool, different IP in DNS.

By the way, when you change the name for the second server in responses, and the client comes back in with a request, will the second server accept it or does it expect that internal name to have been used?

---

<div class="post-metadata">

**Author:** ![Keith\_Fox\_15580](https://avatars.discourse-cdn.com/v4/letter/k/5f9b8f/32.png) [@Keith\_Fox\_15580](https://community.f5.com/u/Keith_Fox_15580)\
**Post date:** [January 16, 2015, 3:17pm UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/9 "2015-01-16T15:17:55Z")

</div>

I believe it is going to expect the internal name to redirect it back to the other site.

---

<div class="post-metadata">

**Author:** ![Keith\_Fox\_15580](https://avatars.discourse-cdn.com/v4/letter/k/5f9b8f/32.png) [@Keith\_Fox\_15580](https://community.f5.com/u/Keith_Fox_15580)\
**Post date:** [January 16, 2015, 4:46pm UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/10 "2015-01-16T16:46:17Z")

</div>

I have setup an irule, and blank stream profile, but it is not changing the URL using the irule I have below, I am sure it is something I am doing wrong.

when HTTP\_REQUEST {

Explicitly disable the stream profile for each request so it doesn’t stay

enabled for subsequent HTTP requests on the same TCP connection.

STREAM::disable

}

when HTTP\_RESPONSE {

Apply stream profile against text responses from the application

if { [HTTP::header value Content-Type] contains “text” }{

```tcl
STREAM::expression {@insideserver.domain.com@outsidserver.domain.com@}

   Enable the stream profile

  STREAM::enable

```

}

}

---

<div class="post-metadata">

**Author:** ![Michael\_Jenkins](https://avatars.discourse-cdn.com/v4/letter/m/43a26b/32.png) [@Michael\_Jenkins](https://community.f5.com/u/Michael_Jenkins)\
**Post date:** [January 16, 2015, 7:21pm UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/11 "2015-01-16T19:21:45Z")

</div>

Can you try to log the request uri and response for me and paste what you get. Something like this…

```tcl
when HTTP_REQUEST {
    log local0. "Request URL: "[HTTP::host][HTTP::uri]"
}
when HTTP_RESPONSE {
    log local0. " Response: Status=[HTTP::status] | Location=[HTTP::header value Location]"
}

```

Otherwise, it could be that you’re getting a 302 or 301 response to redirect to the other page. At that point you would rewrite the Location header. If the link to the other internal host is in the response body, you may want to check out trying to remove the “Accept-Encoding” header (see [STREAM::expression wiki page](https://devcentral.f5.com/wiki/iRules.STREAM__expression.ashx) or one of the notes on [SOL8115([https://support.f5.com/kb/en-us/solutions/public/8000/100/sol8115.html))](https://support.f5.com/kb/en-us/solutions/public/8000/100/sol8115.html)))

---

<div class="post-metadata">

**Author:** ![Keith\_Fox\_15580](https://avatars.discourse-cdn.com/v4/letter/k/5f9b8f/32.png) [@Keith\_Fox\_15580](https://community.f5.com/u/Keith_Fox_15580)\
**Post date:** [January 16, 2015, 8:51pm UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/12 "2015-01-16T20:51:15Z")

</div>

This is the log that I got to the log local, I changed the server names, but it should give you a general idea… really frustrated with this site, and trying to get it to work. Thanks for all the help!

Jan 16 15:20:40 bigip info tmm[15713]: Rule /Common/Log\_rule : Request URL: [publicname.domain.com](http://publicname.domain.com) Jan 16 15:20:40 bigip info tmm[15713]: Rule /Common/Log\_rule : Response: Status=302 | Location=[http://SERVER2.domain.com:80/sso/SSOServlet?\_action=LOGINASSERT&\_ssoOrigUrl=http%3A%2F%2SERVER1.domain.com%3A9080%2Fefs&\_TKM=TODO-UI&\_serviceName=LBIDSP&\_ssoTenant=DEFAULT&\_ssoAuthUrl=http%3A%2F%2SERVER1.domain.com%3A9080%2Fsso%2FSSOServlet&\_ssovaltoken=yGoOGEPj3EBZvpFzWYSVSWj0EIQ%3D](http://SERVER2.domain.com:80/sso/SSOServlet?_action=LOGINASSERT&_ssoOrigUrl=http%3A%2F%252SERVER1.domain.com%3A9080%2Fefs&_TKM=TODO-UI&_serviceName=LBIDSP&_ssoTenant=DEFAULT&_ssoAuthUrl=http%3A%2F%252SERVER1.domain.com%3A9080%2Fsso%2FSSOServlet&_ssovaltoken=yGoOGEPj3EBZvpFzWYSVSWj0EIQ%3D)

---

<div class="post-metadata">

**Author:** ![Michael\_Jenkins](https://avatars.discourse-cdn.com/v4/letter/m/43a26b/32.png) [@Michael\_Jenkins](https://community.f5.com/u/Michael_Jenkins)\
**Post date:** [January 16, 2015, 9:05pm UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/13 "2015-01-16T21:05:40Z")

</div>

Ok. And you said that [server1.domain.com](http://server1.domain.com) and [server2.domain.com](http://server2.domain.com) aren’t internet acessible, but your users are accessing this through internet, so they need [publicname.domain.com](http://publicname.domain.com)? In this case, there’s a couple things you might do. You could follow the ideas in this article ([Rewriting Redirects - F5 Technical Articles - DevCentral - An F5 Technical Community](https://devcentral.f5.com/s/articles/rewriting-redirects)) for the iRule redirect rewriting and replace [server2.domain.com](http://server2.domain.com) and [server1.domain.com](http://server1.domain.com) with [publicname.domain.com](http://publicname.domain.com) and then change the iRule to check for starting with “/sso” and route to the auth pool. Then you still have only one path. The other way would be to have a second dns name like [auth.domain.com](http://auth.domain.com) and do basically the same thing as the other, but in the request, check for [auth.domain.com](http://auth.domain.com) host instead of the uri to decide which pool to send it to. Hope this makes sense.

---

<div class="post-metadata">

**Author:** ![Keith\_Fox\_15580](https://avatars.discourse-cdn.com/v4/letter/k/5f9b8f/32.png) [@Keith\_Fox\_15580](https://community.f5.com/u/Keith_Fox_15580)\
**Post date:** [January 16, 2015, 9:32pm UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/14 "2015-01-16T21:32:06Z")

</div>

I tried using the below irule, and it still doesn’t seem to be re-writing it. I would prefer to have only one outside public domain, but at this point I’ll do two if needed. Naturally I am under a time table to have this site operational by next Friday, so no pressure.

when HTTP\_RESPONSE { if { [HTTP::is\_redirect] }{ HTTP::header replace Location [string map {“[A.internal.com](http://A.internal.com)” “[X.external.com](http://X.external.com)”} [HTTP::header Location]] } }

---

<div class="post-metadata">

**Author:** ![Michael\_Jenkins](https://avatars.discourse-cdn.com/v4/letter/m/43a26b/32.png) [@Michael\_Jenkins](https://community.f5.com/u/Michael_Jenkins)\
**Post date:** [January 17, 2015, 1:10am UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/15 "2015-01-17T01:10:01Z")

</div>

You can try this and see what the logs turn up… Maybe that will help figure something out… Are you familiar with tcpdump too?

```tcl
when HTTP_REQUEST {
    log local0. "URL: [HTTP::host][HTTP::uri]"
}
when HTTP_RESPONSE { 
    log local0. " Response code: [HTTP::status]"
    if { [HTTP::is_redirect] }{ 
        log local0. " Original: [HTTP::header value Location]"
        HTTP::header replace Location [string map {"A.internal.com" "X.external.com"} [HTTP::header Location]] 
        log local0. " Updated: [HTTP::header value Location]"
    } 
}

```

---

<div class="post-metadata">

**Author:** ![What\_Lies\_Bene1](https://avatars.discourse-cdn.com/v4/letter/w/59ef9b/32.png) [@What\_Lies\_Bene1](https://community.f5.com/u/What_Lies_Bene1)\
**Post date:** [January 19, 2015, 9:06am UTC](https://community.f5.com/t/virtual-server-with-two-different-web-servers/20260/16 "2015-01-19T09:06:52Z")

</div>

Just FYI, I’m pretty sure a stream profile won’t rewrite a HTTP header, only the body.
