docker-nginx-auth-request-django-shiny-example icon indicating copy to clipboard operation
docker-nginx-auth-request-django-shiny-example copied to clipboard

How can you do it for more than one shinnyapp?

Open manueLytica opened this issue 5 years ago • 1 comments

manueLytica avatar Jul 28 '20 21:07 manueLytica

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:

pawamoy avatar Jul 29 '20 19:07 pawamoy