Note that there are some explanatory texts on larger screens.

plurals
  1. POPreserving sessions when using multipe domain names for one Rails app
    primarykey
    data
    text
    <p>I have a single Rails 2.2.2 app that I want to 'share' with multiple clients. Each client has his own domain name and database. The purpose is to allow one Rails app to 'host' many websites.</p> <p>I am using Apache as a front end to a mongrel cluster, as the web server. To enable Rails to know which request is for which client, Apache adds a 'client_id' header to each request. Rails uses this 'client_id' to choose the correct database. </p> <p>This works perfectly well as long as I am only accessing it from one domain name at at time. Say 'example1.com'.</p> <p>It even works fine -- mostly -- when many users are accessing the application from multiple domain names at the same time.</p> <p>The one problem I have is that when two users are accessing the application from two domain names at the same time, then <strong>cookies are reset in an unexpected way</strong>.</p> <p>The problem is illustrated in the log snippet below:</p> <p>The 1st request is from User 1 logged into example1.com. </p> <p>The 2nd request is from User 2, for the example2.com home page.</p> <p>The 3rd request is from User 1, for another page in the application. Presumably, the request included the original cookie. <strong>The question is, why did Rails send a different cookie back???</strong></p> <p>Note that, unlike several other questions, <strong>I am not trying to share the same cookie across multiple domains.</strong> User 1 and User 2 in the example above are accessing different domains. </p> <p>-- John</p> <pre><code>**1st Request from USER 1 for example1.com** Processing Admin::CmsController#index (for 75.127.142.66 at 2009-01-27 13:15:27) [GET] Session ID: 00b9cfb6fd397e5c9934ea58eaef648d &gt;&gt;&gt; Request for client 90873721, EXAMPLE1.COM Rendering template within layouts/admin/standard Rendering admin/cms/list Completed in 114ms (View: 14, DB: 81) | 200 OK [https://example1.com/admin/cms] **2nd Request from User 2 for example2.com** Processing CmsController#cms_show (for 64.1.215.163 at 2009-01-27 13:16:15) [GET] Session ID: 4fed1c59001f7484a63fb6280376825a Parameters: {"alias"=&gt;"home.html"} &gt;&gt;&gt; Request for client 48218343, EXAMPLE2.COM ### alias: home.html Rendering template within layouts/two-column Rendering cms/cms_show Completed in 23ms (View: 13, DB: 3) | 200 OK [http://example2.com/] **3rd Request from User 1 for example1.com -- note session ID changes!!!** Processing Admin::CmsController#index (for 75.127.142.66 at 2009-01-27 13:16:18) [GET] Session ID: 85c178aa70ed2bef6a767e844bf6c6d6 &gt;&gt;&gt; Request for client 90873721, EXAMPLE1.COM ####### 'admin/cms', 'index' Redirected to actionsignincontroller/admin/user Filter chain halted as [:check_authentication] rendered_or_redirected. Completed in 4ms | 302 Found [https://example1.com/admin/cms] **4th request -- redirected from 3rd request** Processing Admin::UserController#signin (for 75.127.142.66 at 2009-01-27 13:16:18) [GET] Session ID: 85c178aa70ed2bef6a767e844bf6c6d6 &gt;&gt;&gt; Request for client 90873721, EXAMPLE1.COM Rendering template within layouts/admin/standard Rendering admin/user/signin Completed in 10ms (View: 6, DB: 0) | 200 OK [https://example1.com/admin/user/signin] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload