I understand the reason of errors! When we are using round robin algoritm every new reqest from one user (f.e. get some js or css file) go to different backends (in our case different containers). In this situation user may try to get file from container, where shiny server session did not start (because we start shiny server session in another container - with which we made first connection). To resolve this problem we should bind user to exact container.
worker_processes 1;
events { worker_connections 1024; }
http {
sendfile on;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream myapp1 {
hash $remote_addr;
server your_real_ip:3838 fail_timeout=300 max_conns=150;
server your_real_ip:3839 fail_timeout=300 max_conns=150;
server your_real_ip:3939 fail_timeout=300 max_conns=150;
# server shiny-2:3838;
}
#sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server {
listen 80;
location / {
proxy_pass http://myapp1;
proxy_redirect http://myapp1/ $scheme://$host:$server_port/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
proxy_buffering off;
}
}
}
This nginx config works with docker compose. New challenge is to dynamically update config for docker swarm.