Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.