Using shinyproxy with nginx and a location directive other than `/`

I’m trying to get shinyproxy going on EC2 and am using nginx to reverse proxy. I can get this working just fine when / is the location, but I want the location to be /pilot. For example, in nginx I had something like:

   location /pilot/ {
      rewrite ^/pilot/(.*)$ /$1 break;
      proxy_pass http://127.0.0.1:8080/;
      proxy_redirect http://127.0.0.1:8080/ $scheme://$host/pilot/;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_read_timeout 600s;
      proxy_set_header Host $http_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-Protocol $scheme;
   }

Has anybody gotten this working? I suspect I need a rewrite and I’ve just not done it very well? Also, do I need to change landing-page in application.yml to /pilot? I think I had to do something similar when setting up Jupyter notebooks.

Chris

Hi Chris,

I was having a similar issue and was able to get it to work with help from here. (Unable to get contextPath working)

Basically, I think you want:

  • Be sure to be on the latest shinyproxy (2.0.2 as of this post);
  • You want the server.servlet.context-path instead of the proxy.landing-page setting; see the end of the General section at https://www.shinyproxy.io/configuration/#general ;
  • At least for my nginx setup, I didn’t need a rewrite or a proxy_redirect, and had no trailing / (or path at all) for my proxy_pass.

So for the case of a context path of pilot, I’d have something like…

application.yml:

server:
  servlet:
    context-path: /pilot

proxy:
  ...rest of config...

nginx:

map $http_upgrade $connection_upgrade {
  default upgrade;
  '' close;
}

server {
  listen 80;

  location /pilot/ {
    proxy_pass http://127.0.0.1:8080;
    proxy_http_version 1.1;

    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-Protocol $scheme;

    # websocket headers
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
  }
}

Hope that helps,

1 Like

I’m not particularly proficient with nginx configuration, and the rewrite was a hail Mary based on a different location directive for something kind of similar.

Anyway, that did the trick. You’re an absolute boss. Thank you so much for the reply!

Chris

You’re welcome; glad you got it working!