# Sessions on Rails with Pound and Mongrel

**URL:** <https://www.ruby-forum.com/t/sessions-on-rails-with-pound-and-mongrel/112235>\
**Category:** Rails\
**Created:** [August 16, 2007, 5:50pm UTC](https://www.ruby-forum.com/t/sessions-on-rails-with-pound-and-mongrel/112235 "2007-08-16T17:50:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85e7bf/32.png) [@ant](https://www.ruby-forum.com/u/ant)\
**Post date:** [August 16, 2007, 5:50pm UTC](https://www.ruby-forum.com/t/sessions-on-rails-with-pound-and-mongrel/112235/1 "2007-08-16T17:50:29Z")

</div>

Hi All,

I’m experiencing a problem when using pound with Rails. My set up is I  
have a machine acting as a load balancer running Pound. This listens  
on port 80 and directs requests with a particular URL to two backend  
servers both of which are serving my rails app using mongrel cluster  
on ports 9000,9001 and 9002. There is a problem with sessions even  
though I am storing the session data in my database. If I am logged in  
to my application and then on the next request pound send this to a  
different backend server to the one I logged in on then another  
session gets created and hence I am now logged out. I can see both my  
cookie session\_id change and a new session get created in the  
database.  
I can solve this using stick sessions in pound such that the rails  
cooke is written as my\_app\_session\_id and pound looks for this cookie  
and redirects all request with the same id for this cookie to the same  
backend server. However this shouldn’t be necessary. Does anybody have  
any ideas.

Thanks in advance

Anthony

---

<div class="post-metadata">

**Author:** ![ant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85e7bf/32.png) [@ant](https://www.ruby-forum.com/u/ant)\
**Post date:** [August 16, 2007, 6:01pm UTC](https://www.ruby-forum.com/t/sessions-on-rails-with-pound-and-mongrel/112235/2 "2007-08-16T18:01:35Z")

</div>

On 16 Aug 2007, at 17:49, Ant wrote:

> database.  
> I can solve this using stick sessions in pound such that the rails  
> cooke is written as my\_app\_session\_id and pound looks for this cookie  
> and redirects all request with the same id for this cookie to the same  
> backend server. However this shouldn’t be necessary. Does anybody have  
> any ideas.

I have no problems using Pound and sessions. My settings:

- Use activerecord store for your sessions

- Comment out the \_session\_id key (or whatever it is) that is created  
with your new rails application (my cookie is linked to a domain  
anyway, both locally and in production)

- The pound config looks like this:

One of these three is bound to be the problem.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![ant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85e7bf/32.png) [@ant](https://www.ruby-forum.com/u/ant)\
**Post date:** [August 16, 2007, 6:07pm UTC](https://www.ruby-forum.com/t/sessions-on-rails-with-pound-and-mongrel/112235/3 "2007-08-16T18:07:35Z")

</div>

Hi Peter,

Thanks for the reply. How do I link cookies to a domain. this may  
solve the problems since all requests are going into the same domain  
and then get redirected to different physical backend by Pound.

thanks again

Anthony

---

<div class="post-metadata">

**Author:** ![ant](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85e7bf/32.png) [@ant](https://www.ruby-forum.com/u/ant)\
**Post date:** [August 16, 2007, 6:17pm UTC](https://www.ruby-forum.com/t/sessions-on-rails-with-pound-and-mongrel/112235/4 "2007-08-16T18:17:36Z")

</div>

On 16 Aug 2007, at 18:06, Anthony Underwood wrote:

> Thanks for the reply. How do I link cookies to a domain. this may  
> solve the problems since all requests are going into the same  
> domain and then get redirected to different physical backend by Pound.

It happens automatically 🙂

A user will navigate to [yourdomain.com](http://yourdomain.com) and login (or whatever is  
needed to create a session). At that moment, a cookie with  
\_session\_id as the key and a hash as a value will be created in your  
browser and passed on with each subsequent request. On my MacBook  
Pro, I have a local nameserver that allows me to enter urls like  
“peter.dev.rails” which get redirected to localhost, so I don’t need  
a unique session id identifier for my different rails apps. Using a  
local nameserver also allows me to use the subdomain part as an  
identifier (handled through account\_location) for example.

Best regards

Peter De Berdt
