How do I get the HTTP_HOST from Rails?

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 HTTP_HOST value of the request to find out what the current server is and set these variables accordingly? I am using Apache 2 with Passenger.

+2


source to share


2 answers


Think about what you are looking for request.env["SERVER_ADDR"]

.



+9


source


Are you using 2 servers for load balancing? If so, you won't want to grab the host from the request, because it will be the same in both cases. You will want to grab it in some kind of general ruby ​​call. It has been a while since I made Ruby, but probably something like (untested - rough idea):



Resolv::Hosts.getNames(Resolv::Hosts.getAddress('localhost'))

      

0


source







All Articles