Score:0

Use nginx location blocks with Shinyproxy

br flag

I recently successfully deployed a ShinyProxy + app using SSL with nginx and certbot in the following manner:

  1. Dockerize ShinyProxy + app and launch on port 127.0.0.1:5001.
  2. Create Nginx config and proxy_pass to 127.0.0.1:5001.
  3. Secure using certbot.

This is the successful nginx.conf location section:

    location / {
                     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-Proto $scheme;
                     proxy_set_header        Upgrade $http_upgrade;
                     proxy_set_header        Connection "upgrade";
    
                     proxy_http_version 1.1;
                     proxy_redirect off;
    
                     proxy_read_timeout  90s;
                     proxy_pass          http://127.0.0.1:5001;
           }

This nicely redirects me to https://app.myweb.com/login as I have set up a CNAME. Important to note, {ShinyProxy} redirects to the login at the end automatically. On successful login the url redirects to https://app.myweb.com/app/website.

What I really struggle with is the following: adding a location block or as I understand it, include my upstream block into my downstream (correct my terms if I am wrong). So, have my url go from https://app.myweb.com/login to https://app.myweb.com/dashboard/login using the following configuration in nginx:


location /dashboard/ { # THIS IS WHAT I WANT TO ADD
                     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-Proto $scheme;
                     proxy_set_header        Upgrade $http_upgrade;
                     proxy_set_header        Connection "upgrade";
    
                     proxy_http_version 1.1;
                     proxy_redirect off;
    
                     proxy_read_timeout  90s;
                     proxy_pass          http://127.0.0.1:5001;
           }

All that happens is, if I type https://app.myweb.com/dashboard/ it doesn't go to https://app.myweb.com/dashboard/login as I would expect, but redirects back to https://app.myweb.com/login which 404's.

Any advice on what I am doing wrong?

Score:0
us flag

You need to set up your application's base URL to match the URL nginx is configured with.

Hanjo Odendaal avatar
br flag
Hi @tero-kilkanen, could you perhaps shown some examples? I have set `server_name app.myweb.com` at the top of my `server{}` block if that is what you mean. I have then also set the CNAME to `app.myweb.com`
Score:0
cn flag
location ^~ /dashboard/ { # THIS IS WHAT I WANT TO ADD

Could you try it like this. It may solve your problem.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.