Nicolas St-Laurent
2007-Apr-17 19:44 UTC
[Mongrel] Session problem mongrel behind Apache proxy
Hi, I''ve configured mongrel_clusters behind an Apache 2.2 proxy using named virtual host. Session are saved as ActiveRecordSession. But the cookies created on client side doesn''t correspond to session data saved in database (keys are different). The RoR app react just like it doesn''t have a session at all. If I don''t use Apache as a proxy/load balancer and call directly Mongrel_cluster, everything works well. What should I do to get session working with Mongrel behind an Apache proxy/load balancer ? **** Extract of my Apache config ***** # Setup a cluster for each application <Proxy balancer://myapp> BalancerMember http://10.1.4.22:3000 BalancerMember http://10.1.4.22:3001 BalancerMember http://10.1.4.22:3002 </Proxy> <VirtualHost 10.1.4.22:80> ServerName myapp.xxxxxxxx.yyy DocumentRoot /srv/www/rails/myapp/public <Directory "/srv/www/rails/myapp/public"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> # The root of this virtual host redirect to Portal application ProxyPass / balancer://myapp/ ProxyPassReverse / balancer://myapp/ ProxyPreserveHost on # Make all of the /public/images directory served by Apache ProxyPass /images ! Alias /images /srv/www/rails/myapp/public/images # Setup your Rewrite rules here RewriteEngine On # Rewrite index to check for static RewriteRule ^/$ /index.html [QSA] # Send all requests that are not found as existing files to the cluster RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ balancer://myapp%{REQUEST_URI} [P,QSA,L] # Error logs ErrorLog /var/log/apache2/myapp_error_log CustomLog /var/log/apache2/myapp_access_log combined </VirtualHost>> **** END **** Thanks, Nicolas
On Tue, 17 Apr 2007 15:44:31 -0400 Nicolas St-Laurent <nstlaurent at wantedtech.com> wrote:> Hi, > > I''ve configured mongrel_clusters behind an Apache 2.2 proxy using > named virtual host. Session are saved as ActiveRecordSession. But the > cookies created on client side doesn''t correspond to session data > saved in database (keys are different). The RoR app react just like > it doesn''t have a session at all. > > If I don''t use Apache as a proxy/load balancer and call directly > Mongrel_cluster, everything works well. > > What should I do to get session working with Mongrel behind an Apache > proxy/load balancer ?Not sure if you''ve solved this yet, but you can find out what Apache is sending to Mongrel by doing this: 1) mongrel_rails start -B 2) Make some requests that should have cookies. 3) look in log/mongrel_debug/rails.log for the headers being given to Mongrel. That''ll give you a clue as to what is going on. -- Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu http://www.zedshaw.com/ http://www.awprofessional.com/title/0321483502 -- The Mongrel Book http://mongrel.rubyforge.org/
> Hi, > > I''ve configured mongrel_clusters behind an Apache 2.2 proxy using > named virtual host. Session are saved as ActiveRecordSession. But the > cookies created on client side doesn''t correspond to session data > saved in database (keys are different). The RoR app react just like > it doesn''t have a session at all. > > If I don''t use Apache as a proxy/load balancer and call directly > Mongrel_cluster, everything works well. > > What should I do to get session working with Mongrel behind an Apache > proxy/load balancer ?I''m curious -- did you find a solution to this problem. We have recently moved from a single mongrel thread to a placing mongrel behind Apache''s load balancer and we are running into the same problem -- the initial request to the application initiates a session, but subsequent requests fail because the session data is empty. Like you, if we don''t use the load balancer it works fine. --TR ******************************************* Terry Reese Cataloger for Networked Resources Digital Production Unit Head Oregon State University Libraries Corvallis, OR 97331 tel: 541-737-6384 email: terry.reese at oregonstate.edu http: http://oregonstate.edu/~reeset ******************************************* -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20070424/b66b9866/attachment.html
On 4/25/07, Reese, Terry <terry.reese at oregonstate.edu> wrote:> > Hi, > > > > I''ve configured mongrel_clusters behind an Apache 2.2 proxy using > > named virtual host. Session are saved as ActiveRecordSession. But the > > cookies created on client side doesn''t correspond to session data > > saved in database (keys are different). The RoR app react just like > > it doesn''t have a session at all. > > > > If I don''t use Apache as a proxy/load balancer and call directly > > Mongrel_cluster, everything works well. > > > > What should I do to get session working with Mongrel behind an Apache > > proxy/load balancer ? > > I''m curious -- did you find a solution to this problem. We have recently > moved from a single mongrel thread to a placing mongrel behind Apache''s load > balancer and we are running into the same problem -- the initial request to > the application initiates a session, but subsequent requests fail because > the session data is empty. Like you, if we don''t use the load balancer it > works fine.We''ve been working with the exact situation you both outline above, but we''ve had no issues like you''ve described. To be clear, we''ve got: 6 mongrels (clustered) Apache 2.2 proxying and load balancing, (as well as handling the static content) Would you mind posting your Apache Virtual Host block? My guess is a misconfiguration there. Sean
Could be -- this is the first time using the balancer with Mongrel so something could be out of wack. Anyway, here''s the Virtual Host code block. Thanks, --TR # Virtual Hosts # # If you want to maintain multiple domains/hostnames on your # machine you can setup VirtualHost containers for them. Most configurations # use only name-based virtual hosts so the server doesn''t need to worry about # IP addresses. This is indicated by the asterisks in the directives below. # # Please see the documentation at # <URL:http://httpd.apache.org/docs/2.2/vhosts/> # for further details before you try to setup virtual hosts. # # You may use the command line option ''-S'' to verify your virtual host # configuration. # # Use name-based virtual hosting. # NameVirtualHost 128.193.xxx.xx:80 <VirtualHost 128.193.xxx.xx:80> SetEnv RAILS_ENV production ServerName search3.library.oregonstate.edu ServerAdmin terry.reese at oregonstate.edu DocumentRoot /usr/local/apache-lf3/rails/public/ ErrorLog /usr/local/apache-lf3/rails/log/error.log CustomLog /usr/local/apache-lf3/rails/log/access.log common RewriteEngine On RewriteRule ^(.*/)?.svn/ - [F,L] ProxyPass /images/ ! ProxyPass /stylesheets/ ! ProxyPass /javascripts/ ! ProxyPass /error/ ! ProxyPass /icons/ ! ProxyPass / balancer://libraryfind/ ProxyPassReverse / balancer://libraryfind/ ProxyPreserveHost On <Proxy balancer://libraryfind> BalancerMember http://127.0.0.1:4010 BalancerMember http://127.0.0.1:4011 BalancerMember http://127.0.0.1:4012 BalancerMember http://127.0.0.1:4013 BalancerMember http://127.0.0.1:4014 </Proxy> <Directory "/usr/local/apache-lf3/rails/public"> Options +FollowSymlinks +ExecCGI AllowOverride All Order allow,deny Allow from all </Directory> ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly" ErrorDocument 502 "<h2>Application error</h2>Unable to talk to back-end service" </VirtualHost>> -----Original Message----- > From: mongrel-users-bounces at rubyforge.org > [mailto:mongrel-users-bounces at rubyforge.org] On Behalf Of Sean Brown > Sent: Wednesday, April 25, 2007 9:09 AM > To: mongrel-users at rubyforge.org > Subject: Re: [Mongrel] Session problem mongrel behind Apache proxy > > On 4/25/07, Reese, Terry <terry.reese at oregonstate.edu> wrote: > > > Hi, > > > > > > I''ve configured mongrel_clusters behind an Apache 2.2 proxy using > > > named virtual host. Session are saved as ActiveRecordSession. But > > > the cookies created on client side doesn''t correspond to session > > > data saved in database (keys are different). The RoR app > react just > > > like it doesn''t have a session at all. > > > > > > If I don''t use Apache as a proxy/load balancer and call directly > > > Mongrel_cluster, everything works well. > > > > > > What should I do to get session working with Mongrel behind an > > > Apache proxy/load balancer ? > > > > I''m curious -- did you find a solution to this problem. We have > > recently moved from a single mongrel thread to a placing mongrel > > behind Apache''s load balancer and we are running into the > same problem > > -- the initial request to the application initiates a session, but > > subsequent requests fail because the session data is empty. > Like you, > > if we don''t use the load balancer it works fine. > > > We''ve been working with the exact situation you both outline > above, but we''ve had no issues like you''ve described. To be > clear, we''ve > got: > > 6 mongrels (clustered) > Apache 2.2 proxying and load balancing, (as well as handling > the static content) > > Would you mind posting your Apache Virtual Host block? My > guess is a misconfiguration there. > > Sean > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users >
Just an FYI -- the problem solved itself by moving away from ActiveRecord and using either memcache or SqlSession. Thanks, --TR> -----Original Message----- > From: mongrel-users-bounces at rubyforge.org > [mailto:mongrel-users-bounces at rubyforge.org] On Behalf Of Sean Brown > Sent: Wednesday, April 25, 2007 9:09 AM > To: mongrel-users at rubyforge.org > Subject: Re: [Mongrel] Session problem mongrel behind Apache proxy > > On 4/25/07, Reese, Terry <terry.reese at oregonstate.edu> wrote: > > > Hi, > > > > > > I''ve configured mongrel_clusters behind an Apache 2.2 proxy using > > > named virtual host. Session are saved as ActiveRecordSession. But > > > the cookies created on client side doesn''t correspond to session > > > data saved in database (keys are different). The RoR app > react just > > > like it doesn''t have a session at all. > > > > > > If I don''t use Apache as a proxy/load balancer and call directly > > > Mongrel_cluster, everything works well. > > > > > > What should I do to get session working with Mongrel behind an > > > Apache proxy/load balancer ? > > > > I''m curious -- did you find a solution to this problem. We have > > recently moved from a single mongrel thread to a placing mongrel > > behind Apache''s load balancer and we are running into the > same problem > > -- the initial request to the application initiates a session, but > > subsequent requests fail because the session data is empty. > Like you, > > if we don''t use the load balancer it works fine. > > > We''ve been working with the exact situation you both outline > above, but we''ve had no issues like you''ve described. To be > clear, we''ve > got: > > 6 mongrels (clustered) > Apache 2.2 proxying and load balancing, (as well as handling > the static content) > > Would you mind posting your Apache Virtual Host block? My > guess is a misconfiguration there. > > Sean > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users >