# F5 as web server

**URL:** <https://community.f5.com/t/f5-as-web-server/40081>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [October 17, 2008, 6:21pm UTC](https://community.f5.com/t/f5-as-web-server/40081 "2008-10-17T18:21:53Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_90553](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@Tim\_90553](https://community.f5.com/u/Tim_90553)\
**Post date:** [October 17, 2008, 6:21pm UTC](https://community.f5.com/t/f5-as-web-server/40081/1 "2008-10-17T18:21:53Z")

</div>

Can the F5 serve a web page from it’s local file system?

---

<div class="post-metadata">

**Author:** ![Richard\_Jones](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@Richard\_Jones](https://community.f5.com/u/Richard_Jones)\
**Post date:** [October 17, 2008, 8:59pm UTC](https://community.f5.com/t/f5-as-web-server/40081/2 "2008-10-17T20:59:23Z")

</div>

You can return html content directly from an iRule:

when HTTP\_REQUEST {

HTTP::respond 200 content {

\

\

Apology Page \

\

\

We are sorry, but the site you are looking for is temporarily out of service

\

If you feel you have reached this page in error, please try again. \

\

}

}

See: [http://devcentral.f5.com/Wiki/default.aspx/iRules/HTTP\_\_respond.html](http://devcentral.f5.com/Wiki/default.aspx/iRules/HTTP%5C_%5C_respond.html)

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [October 17, 2008, 9:21pm UTC](https://community.f5.com/t/f5-as-web-server/40081/3 "2008-10-17T21:21:30Z")

</div>

Sorry, wpskier, I updated the HTTP::respond wiki page with a bad example today. You can remove the trailing backslashes as they aren’t needed with the outer curly braces:

```tcl
when HTTP_REQUEST { 
    HTTP::respond 200 content { 
        
           
             Apology Page 
           
           
             We are sorry, but the site you are looking for is temporarily out of service
 
             If you feel you have reached this page in error, please try again. 
           
        
    } 
 }

```

Aaron

---

<div class="post-metadata">

**Author:** ![pgroven\_71837](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pgroven\_71837](https://community.f5.com/u/pgroven_71837)\
**Post date:** [December 5, 2008, 10:34pm UTC](https://community.f5.com/t/f5-as-web-server/40081/4 "2008-12-05T22:34:17Z")

</div>

I need to do something similar but the http conversion would be a two step process

the 200 repsonse from the F5 will need to look like this

HTTP/1.1 200 OK

Date: Wed, 03 Dec 2008 21:37:28 GMT

Server: Apache/2.0.52 (Red Hat) mod\_ssl/2.0.52 OpenSSL/0.9.7a

Cache-Control: private

Content-Length: 477

Set-Cookie: JSESSIONID=aVQF4FC9UlQc; path=/

Keep-Alive: timeout=15, max=100

Connection: Keep-Alive

Content-Type: text/plain; charset=utf-8

1

the client response will be like this

POST / HTTP/1.1

Accept: text/\*, application/\*

Host: 12.23.2.12:443

Content-Length: 0

Connection: Keep-Alive

Content-Type: text/xml; charset=“utf-8”

Cookie: JSESSIONID=aVQF4FC9UlQc

Authorization:Basic MDAwRkNDLTEzNjMDA3NzAyNDoxMjM0NTY=

this reply from F5 tells the client to go away

HTTP/1.1 204 No Content

Date: Wed, 03 Dec 2008 21:37:29 GMT

Server: Apache/2.0.52 (Red Hat) mod\_ssl/2.0.52 OpenSSL/0.9.7a

Content-Length: 0

Keep-Alive: timeout=15, max=99

Connection: Keep-Alive

Content-Type: text/plain; charset=utf-8

Can this two step http conversation take place?

this traffic will be all ssl so the F5 would have to offload the ssl transaction first

how would this irule be coded?

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [December 8, 2008, 11:29am UTC](https://community.f5.com/t/f5-as-web-server/40081/5 "2008-12-08T11:29:33Z")

</div>

Hi pgroven,

You can use HTTP::respond to send an arbitrary HTTP response to the client. If you want to send two different responses based on some component of the request you’d need to check the client request first. When do you want to send the HTTP 200 response and when do you want to send the HTTP 204 response?

You can check the HTTP::response wiki page ([Click here](http://devcentral.f5.com/wiki/default.aspx/iRules/http__respond)) for details on using the command.

Aaron

---

<div class="post-metadata">

**Author:** ![pgroven\_71837](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pgroven\_71837](https://community.f5.com/u/pgroven_71837)\
**Post date:** [December 8, 2008, 3:53pm UTC](https://community.f5.com/t/f5-as-web-server/40081/6 "2008-12-08T15:53:33Z")

</div>

as shown above the 200 response will come first

The client will respond with something like this

(IP address and authorization will be different for each client)

POST / HTTP/1.1

Accept: text/\*, application/\*

Host: 12.23.2.12:443

Content-Length: 0

Connection: Keep-Alive

Content-Type: text/xml; charset=“utf-8”

Cookie: JSESSIONID=aVQF4FC9UlQc

Authorization:Basic MDAwRkNDLTEzNjMDA3NzAyNDoxMjM0NTY=

after this the F5 response should be like this

Can the irule be configured to display correct time?

HTTP/1.1 204 No Content

Date: Wed, 03 Dec 2008 21:37:29 GMT

Server: Apache/2.0.52 (Red Hat) mod\_ssl/2.0.52 OpenSSL/0.9.7a

Content-Length: 0

Keep-Alive: timeout=15, max=99

Connection: Keep-Alive

Content-Type: text/plain; charset=utf-8

I am not sure how I can code this irule?

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [December 8, 2008, 4:57pm UTC](https://community.f5.com/t/f5-as-web-server/40081/7 "2008-12-08T16:57:15Z")

</div>

Is there a particular scenario that you want to enable the 204 response from the iRule? You can use the TCL clock command (clock format with clock seconds [Click here](http://www.tcl.tk/man/tcl8.4/TclCmd/clock.htm)) to get the current time in a specific format.

Aaron

---

<div class="post-metadata">

**Author:** ![pgroven\_71837](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pgroven\_71837](https://community.f5.com/u/pgroven_71837)\
**Post date:** [December 8, 2008, 7:45pm UTC](https://community.f5.com/t/f5-as-web-server/40081/8 "2008-12-08T19:45:42Z")

</div>

this irule will be implemented during a maintenance window so the cluster can recover quicker once it is started backup.

Can an irule be specified for only one pool?

---

<div class="post-metadata">

**Author:** ![Colin\_Walker\_12](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@Colin\_Walker\_12](https://community.f5.com/u/Colin_Walker_12)\
**Post date:** [December 8, 2008, 8:08pm UTC](https://community.f5.com/t/f5-as-web-server/40081/9 "2008-12-08T20:08:57Z")

</div>

iRules are specified at the Virtual Server level, not at the pool level. You can certainly make the iRule only act on certain traffic, though.

Colin

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [December 8, 2008, 8:12pm UTC](https://community.f5.com/t/f5-as-web-server/40081/10 "2008-12-08T20:12:52Z")

</div>

Hi pgroven,

As Colin suggests, it’s possible to send a response based on specific criteria of the request and/or response. If you’re looking for specific suggestions for how to write an iRule to send back a response, could you provide more complete information on what you’re overall goal and what you want to do with an iRule? Else, if you try something and get stuck let us know.

Thanks,

Aaron

---

<div class="post-metadata">

**Author:** ![pgroven\_71837](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pgroven\_71837](https://community.f5.com/u/pgroven_71837)\
**Post date:** [April 13, 2009, 5:37pm UTC](https://community.f5.com/t/f5-as-web-server/40081/11 "2009-04-13T17:37:50Z")

</div>

Sometimes I use the following simple irule

when HTTP\_REQUEST {

HTTP::respond 204

}

Is there any way to setup a counter to log how many connections were handed a 204?

Can it be sent to /var/log/ltm?

---

<div class="post-metadata">

**Author:** ![L4L7\_53191](https://avatars.discourse-cdn.com/v4/letter/l/f475e1/32.png) [@L4L7\_53191](https://community.f5.com/u/L4L7_53191)\
**Post date:** [April 13, 2009, 6:10pm UTC](https://community.f5.com/t/f5-as-web-server/40081/12 "2009-04-13T18:10:03Z")

</div>

Yes.

```tcl
when HTTP_REQUEST { 
 HTTP::respond 204 
 log local0. "Sent a 204!" 
 }

```

…Will go to /var/log/ltm.

-Matt

---

<div class="post-metadata">

**Author:** ![pgroven\_71837](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pgroven\_71837](https://community.f5.com/u/pgroven_71837)\
**Post date:** [April 15, 2009, 12:11am UTC](https://community.f5.com/t/f5-as-web-server/40081/13 "2009-04-15T00:11:56Z")

</div>

will this log be cumulative?

This 204 irule when invoked will send out hundreds of thousands of 204’s every hour.

---

<div class="post-metadata">

**Author:** ![dennypayne](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/dennypayne/32/1364_2.png) [@dennypayne](https://community.f5.com/u/dennypayne)\
**Post date:** [April 15, 2009, 4:13pm UTC](https://community.f5.com/t/f5-as-web-server/40081/14 "2009-04-15T16:13:51Z")

</div>

Yeah you probably don’t want to do that then, you’ll fill up /var/log very quickly. You could log to a localX facility that you set up to send to a remote syslog server, but there’s not really a good way to get statistics like you are looking for out of an iRule. You could increment a counter variable each time it was sent, but I can’t think of a way to periodically log that counter.

Denny

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [April 15, 2009, 5:07pm UTC](https://community.f5.com/t/f5-as-web-server/40081/15 "2009-04-15T17:07:38Z")

</div>

You could use the ‘b rule send\_204\_rule stats’ to view the number of times the HTTP\_REQUEST event has run since the config was last reloaded. Or as Denny suggested, you could use a global variable which counts the execution time. You’d want to add logic to log the current total every X number of seconds or X number of executions (Codeshare example: [Click here](http://devcentral.f5.com/wiki/default.aspx/iRules/LogEveryXSeconds.html)). Or you could use a stats profile (article: [Click here](http://devcentral.f5.com/Default.aspx?tabid=63&articleType=ArticleView&articleId=66)). The stats is accessible via the GUI (and should be accessible via SNMP, but due to a bug, CR117258, this doesn’t work in 9.4.6).

Aaron
