Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1067243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:07:58+00:00 2026-05-16T20:07:58+00:00

I’m using Nginx with Phusion Passenger to run a Rails app on an EC2

  • 0

I’m using Nginx with Phusion Passenger to run a Rails app on an EC2 CentOS machine.

I have a pretty standard set up with Nginx, Rails, Phusion Passenger and SSL (I think). My nginx.conf is below. So far it has worked out fine except that every time two requests hit the server at the same time, a new Rails instance is created to serve the second request.

The problem is that once the second request is directed to the newly created Rails instance, it loses the authenticated session from the original Rails instance, resulting in errors. My sessions are stored in memory.

As a workaround, I’ve set passenger_max_instances_per_app to 1 so on new Rails instances are created, but this is only a temporary fix.

Does anyone know how to make Nginx maintain the same session for requests from the same source? I might be missing something obvious here.

Thanks!

worker_processes  1;  

events {
    worker_connections  1024;
}

http {
    ...
    passenger_pool_idle_time 0;
    passenger_max_instances_per_app 1;

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on; 
    keepalive_timeout  65;   

    # this server isn't rails enabled. 
    # will redirect all traffic to https
    server {
        listen       80; 
        server_name  example.com;
        rewrite ^ https://www.example.com$request_uri permanent;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }   
    }   

    # HTTPS server
    # - by default everything is served by https
    server {
        listen       443;
        server_name  www.example.com;
        root   /rails/root/public;
        passenger_enabled on;
        rails_env production;

        ssl                  on;
        ssl_certificate      /path/to/cert/www.example.com.crt;
        ssl_certificate_key  /path/to/cert/www.example.com.key;
        ssl_session_timeout  5m;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:07:59+00:00Added an answer on May 16, 2026 at 8:07 pm

    We generally have passenger_max_pool_size 2; unless we leave it out entirely (taking the default setting) and the two settings you’re specifying, passenger_pool_idle_time and passenger_max_instances_per_app we also leave to the default.

    The session key should be kept in a cookie so Rails can look it up between requests. Assuming that’s working properly, the problem is that multiple Rails instances aren’t sharing memory (feature, not a bug – they’re processes, not threads) and therefore don’t share session data. Try moving your session information into ActiveRecord:

    # Use the database for sessions instead of the cookie-based default,
    # which shouldn't be used to store highly confidential information
    # (create the session table with "rake db:sessions:create")
    ActionController::Base.session_store = :active_record_store
    

    (the above code is in config/initializers/session_store.rb)

    That way, because the data store is accessibly to multiple Rails processes, they should all have access to the same pool of active sessions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.