views:

357

answers:

2

I need to set some server specific variables in a rails application that will run on at least two different servers. What is the best way to get the request's HTTP_HOST value in order to know what is the current server and set these variables accordingly? I'm using Apache 2 with Passenger.

A: 

Are the 2 servers involved in load balancing? If so, you won't want to grab the host from the request, because it'll be the same in both cases. You'll want to grab it in some generic ruby call. It's been a while since I've done Ruby, but probably something like (untested - rough idea):

Resolv::Hosts.getNames(Resolv::Hosts.getAddress('localhost'))
andersonbd1
Hello, no, these two servers are completely independent. One of them is identical to the production server (so as to test the app under production settings, etc) and the other one is used for development.
zero_padded
+2  A: 

Think you're looking for request.env["SERVER_ADDR"].

hgimenez