Vic*_*ang 6 django load-balancing django-sessions amazon-elastic-beanstalk sticky-session
我在Elastic Load Balancer(ELB)后面使用AWS Elastic Beanstalk和EC2服务器.
我在ELB上启用了"粘性会话",因为这是我可以让django用户会话正常工作的唯一方法.但是,在高峰流量时,这会导致问题,因为ELB不再均匀地分配每个传入请求.这通常会像迷你DDOS一样超载1台服务器.
我想要做的是使用服务器端用户会话,其中用户身份验证信息存储在我的Redis缓存中.我试过设置SESSION_ENGINE
很多东西,比如:
SESSION_ENGINE = 'redis_sessions.session'
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'
Run Code Online (Sandbox Code Playgroud)
然后,当我关闭粘性会话时,我无法登录,因为请求最终会转到不同的服务器,其中某些请求已经过身份验证而其他请求未经过身份验证.那些不是,将我重定向回登录页面.
以下是我的一些其他相关设置:
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',
...,
)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?非常感谢.
您确定您的所有 Web 服务器实际上都连接到同一个共享 Redis 实例,例如:在 AWS ElastiCache 等网络上(而不是默认连接到其本地主机上的某些内容)?
如果您使用SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
,请确保将其使用的缓存设置为您在 中配置的 redis 缓存CACHES
,如果SESSION_CACHE_ALIAS
没有,则可以使用default
。
归档时间: |
|
查看次数: |
833 次 |
最近记录: |