# SCGI cluster configuration example for Apache

**URL:** <https://www.ruby-forum.com/t/scgi-cluster-configuration-example-for-apache/49698>\
**Category:** Rails\
**Created:** [December 7, 2005, 8:02pm UTC](https://www.ruby-forum.com/t/scgi-cluster-configuration-example-for-apache/49698 "2005-12-07T20:02:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![francois.beausoleil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/b487fb/32.png) [@francois.beausoleil](https://www.ruby-forum.com/u/francois.beausoleil)\
**Post date:** [December 7, 2005, 8:02pm UTC](https://www.ruby-forum.com/t/scgi-cluster-configuration-example-for-apache/49698/1 "2005-12-07T20:02:52Z")

</div>

Hi all !

I have SCGI setup and working correctly on a new host. I configured a  
cluster using:  
scgi\_cluster config -e production -p 20000 -c 2

Now, I want to tell mod\_scgi that I have two children. How do I do  
that ? I can’t seem to find anything on the SRR site, nor on the  
mailing list.

Thanks for any tips !

---

<div class="post-metadata">

**Author:** ![francois.beausoleil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/b487fb/32.png) [@francois.beausoleil](https://www.ruby-forum.com/u/francois.beausoleil)\
**Post date:** [December 7, 2005, 11:33pm UTC](https://www.ruby-forum.com/t/scgi-cluster-configuration-example-for-apache/49698/2 "2005-12-07T23:33:03Z")

</div>

You know, I could have swore I did this to test the cluster, but now  
that  
I look at my setup I think it actually wasn’t working with a cluster.  
I’m  
actually quite stumped how you’d do this. In lighttpd you just say  
there’s 3 servers and that’s it. It uses them. In Apache I’m thinking  
you’ll have to scgimount the three backends to different URLs, and then  
_somehow_ use mod\_rewrite to balance between them.

That seriously can’t be right. There’s got to be a simpler way. Anyone  
have other thoughts?

Zed

---

<div class="post-metadata">

**Author:** ![francois.beausoleil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/b487fb/32.png) [@francois.beausoleil](https://www.ruby-forum.com/u/francois.beausoleil)\
**Post date:** [December 9, 2005, 8:21am UTC](https://www.ruby-forum.com/t/scgi-cluster-configuration-example-for-apache/49698/3 "2005-12-09T08:21:40Z")

</div>

2005/12/8, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> You know, I could have swore I did this to test the cluster, but now that  
> I look at my setup I think it actually wasn’t working with a cluster. I’m  
> actually quite stumped how you’d do this. In lighttpd you just say  
> there’s 3 servers and that’s it. It uses them. In Apache I’m thinking  
> you’ll have to scgimount the three backends to different URLs, and then  
> _somehow_ use mod\_rewrite to balance between them.

One could use random RewriteMap for “balancing”. 🙂  
In Apache config:

SCGIMount /scgi0/ 127.0.0.1:9999  
SCGIMount /scgi1/ 127.0.0.1:10000  
SCGIMount /scgi2/ 127.0.0.1:10001

RewriteMap scginums rnd:/web/scgi-nums.txt

File /web/scgi-nums.txt:

num 0|1|2

And change rewrite rule to “balance” between them:

RewriteRule ^(.\*)$ /scgi${scginums:num}/$1 [QSA,L]

Setup Rails routing:  
config/routes.rb:

map.connect ‘:controller/:action/:id’  
map.connect ‘scgi0/:controller/:action/:id’  
map.connect ‘scgi1/:controller/:action/:id’  
map.connect ‘scgi2/:controller/:action/:id’

Now, it will work as a cluster, but it’s definitely _very poor_  
“solution”. 🙂
