docker-nginx-auth-request-django-shiny-example
docker-nginx-auth-request-django-shiny-example copied to clipboard
How can you do it for more than one shinnyapp?
You can declare as many views as you have Shiny apps:
@login_required
def shiny_app1(request):
response = requests.get('http://shinyapp:8101')
soup = BeautifulSoup(response.content, 'html.parser')
return JsonResponse({'html_contents': str(soup)})
@login_required
def shiny_app2(request):
response = requests.get('http://shinyapp:8102')
soup = BeautifulSoup(response.content, 'html.parser')
return JsonResponse({'html_contents': str(soup)})
Then declare as much upstream servers in NginX config:
upstream shinyapp_server1 {
server shinyapp:8101;
}
upstream shinyapp_server2 {
server shinyapp:8102;
}
And redirect to the right one based on the URL:
location ~ /shinyapp1/.+ {
auth_request /auth;
rewrite ^/shinyapp1/(.*)$ /$1 break;
proxy_pass http://shinyapp_server1;
proxy_redirect http://shinyapp_server1/ $scheme://$host/shinyapp1/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
proxy_buffering off;
}
location ~ /shinyapp2/.+ {
auth_request /auth;
rewrite ^/shinyapp2/(.*)$ /$1 break;
proxy_pass http://shinyapp_server2;
proxy_redirect http://shinyapp_server2/ $scheme://$host/shinyapp2/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
proxy_buffering off;
}
It is probably possible to factorize the NginX config, I'm no expert here :slightly_smiling_face: