Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:

127.0.0.1       cdn1.localhost
127.0.0.1       cdn2.localhost
127.0.0.1       cdn3.localhost
127.0.0.1       cdn4.localhost
127.0.0.1       cdn5.localhost

Thanks

--

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

3 Answers 3

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

 
discard

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.