I'm using AWS Elastic Beanstalk with EC2 servers behind an Elastic Load Balancer (ELB).
I have "sticky sessions" on the ELB enabled because that's the only way I can get django user sessions to work correctly. However, during times of peak traffic, this causes problems because the ELB no longer distributes each incoming request evenly. This usually overloads 1 server like a mini DDOS.
What I would like to do is use server-side user sessions where user authentication information is stored in my Redis cache. I've tried setting SESSION_ENGINE
to numerous things like:
SESSION_ENGINE = 'redis_sessions.session'
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'
Then when I turn sticky sessions off, I am unable to login because the requests end up going to different servers where some requests are authenticated and others are not. The ones that are not, redirect me back to the login page.
Here are some other relevant settings I have:
INSTALLED_APPS = (
...,
'django.contrib.sessions',
...,
)
MIDDLEWARE_CLASSES = (
...,
'djangosecure.middleware.SecurityMiddleware',
...,
'django.contrib.sessions.middleware.SessionMiddleware',
...,
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
...,
)
What am I doing wrong? Many thanks.