I'm having a hard time making a connection sticky on my nginx.conf file. the current architecture is as follows
events {}
http {
upstream flask-app {
server flask-app:5000;
}
server {
listen 80;
location / {
proxy_pass http://flask-app;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
flask-app
is a Python-based container that I scale up to 3 of them, the round-robin balancing works fine when I scale the containers up and my idea is that when I connect to a container I want this connection to be persistent for 5 minutes and then switch to another container and again after 5 minutes switch to another one
I want to do this with the help of an nginx container that runs the above conf file with this docker-compose file
version: '3.8'
services:
flask-app:
build:
context: ./webapp
dockerfile: dockerfile
volumes:
- ./logs/flask-app.log:/app/flask-app.log
ports:
- "5000"
depends_on:
- db
restart: on-failure
nginx:
image: nginx
volumes:
- ./nginx.conf/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- flask-app
ports:
- "80:80"
db:
build:
context: .
dockerfile: dockerfile
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=access_log
volumes:
- data:/var/lib/mysql
ports:
- "33012:3306"
volumes:
data:
I scale the flask-app
container when I up the compose docker-compose up -d --build --scale flask-app=3
all of the solutions I've seen require NginxPlus, and for NginxPlus free trial you require to have a business mail which I don't have.
I do have a cookie with a lifetime of 5 minutes in my flask code, this cookie containes the internal IP of the container which you connect to, I am somewhat convinced that using this cookie will be key
I'd love some help in this matter <3
what did I already try - I've already tried pulling custom DockerHub images and making my session persistent through Python but I specifically need nginx sticky cookie for this task