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 2 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 2nd 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 temp 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;
}
}