Take the 2-minute tour ×

I want to define an environment variable as a random number, say like between 1 and 10 in my httpd.conf. Is this possible?

I'm using mod_proxy_html and I want to rewrite some URLs to simulate a CDN, so I would need to define something like this:

ProxyHTMLURLMap /myapp http://cdn${RAND_DIGIT|1}.localhost/myapp [V]

Later on, my hosts file will be like this:       cdn1.localhost       cdn2.localhost       cdn3.localhost       cdn4.localhost       cdn5.localhost



Clarification: I'm using this technique for static resources such as javascript, css, etc. So the session affinity problem does not arise.

share|improve this question
add comment

3 Answers

You can use mod_proxy_balancer Apache module.

With random numbers will not work session.

share|improve this answer
Check my edit/clarification –  Miguel Ping Feb 24 '11 at 18:10
add comment

The variable will only be read on start-up, so it will stay going to the same CDN until Apache restarts.

You could look at some form of round-robin DNS, but that would require setting up a local DNS server.

share|improve this answer
add comment

You can use the rnd MapType with RewriteMap in mod_rewite.

share|improve this answer
I can't seem to use the ${servers:dynamic} syntax outside of Rewrite Rules –  Miguel Ping Feb 24 '11 at 18:17
@MiguelPing: It works in mod_rewrite. –  Dennis Williamson Feb 24 '11 at 18:59
add comment

Your Answer


