Proxy rstudio-server and shiny-server at the same time

I am trying to set up an Apache2 proxy server on a host that serves Tomcat webapps, a Shiny server, and RStudio server. Apache is set up to redirect http to https, and all of my proxy settings are in the default-ssl.conf file, shown below.

Proxies to Tomcat (using ajp_13) work fine.

Proxy to Shiny server mostly works correctly, as long as the address is typed into the address bar. The same address, if clicked or pasted, drops the "shiny" portion. (e.g. https:// my.host.com/shiny/users/me/hello becomes https:// my.host.com/users/me if I click or paste,but works if I type it out.)

Proxying to rstudio-server - well, if I type in the host address followed by /rstudio, it immediately redirects to the host address followed by auth-sign-in (rather than /rstudio/auth-sign-in). If I type in the full path to auth-sign-in, I can sign in, but then it redirects to the base server address rather than /rstudio. If I then type in the base address followed by /rstudio, I get rstudio, and it works fine from then on.

Here is my config: (note - spaces in the addresses are because I'm a new user and it won't let me have more than two "links" in my post.)

<VirtualHost _default_:443>

   ...
 <Proxy *>
                  Allow from localhost
                </Proxy>

                ProxyPreserveHost On
                RewriteEngine on

                RedirectMatch permanent ^/rstudio$ /rstudio/

                RewriteCond %{HTTP:Upgrade} =websocket
                RewriteRule /rstudio/(.*)     ws:// localhost:8787/$1  [P,L]

                RewriteCond %{HTTP:Upgrade} !=websocket
                RewriteRule /rstudio/(.*)     http:// localhost:8787/$1 [P,L]

                ProxyPass /rstudio/ http://localhost:8787/
                ProxyPassReverse /rstudio/ http:// localhost:8787/

                Header edit Location ^/ /rstudio/

                RedirectMatch permanent ^/shiny$ /shiny/

                RewriteCond %{HTTP:Upgrade} =websocket
                RewriteRule /shiny/(.*) ws:// localhost:3838/$1 [P,L]

                RewriteCond %{HTTP:Upgrade} !=websocket
                RewriteRule /shiny/(.*) http:// localhost:3838/$1 [P,L]

                ProxyPass /shiny/ http:// localhost:3838/
                ProxyPassReverse /shiny/ http:// localhost:3838/

                ProxyRequests Off
    ...
</VirtualHost>

I know I can solve this with virtual servers, but if possible I'd really like it to work without. If anyone can steer me in the right direction, I'd really appreciate it.

Have you compared your configuration with the following documentation?

I find the line Header edit Location ^/ /rstudio/ odd. Such a line is only mentioned in the documentation for Shiny Server, not foir RStudio Server. I have not need this line in similar configs in the past, so I would try to remove it.

I have tried both with and without that line - oddly it appears to have no effect whatsoever on the behavior of either server.

Also, those documents were where I started my journey. I got shiny working first by following the instructions from the second link, then added rstudio-server and that's when the problems started. I'm clearly missing something but I can't see what it is. I've tried various combinations of suggestions from Stack and the Apache mod-rewrite and mod-proxy documentation. It seems crazy to me that these two servers wouldn't work together on the same system - and in fact, I know they do because I've used them on the same system before. I didn't install them on that system, though, and don't have it around any more for reference.

This is strange. I will try to find the time to test such a set-up.

tl;dr: Remove ProxyPreserveHost On from your config. This is not one of the special cases the documentation talks about.

I reproduced the issue using a docker-compose.yml like this:

version: '2.3'
services:
    rstudio:
        image: rocker/rstudio
        environment:
        - PASSWORD=rstudio12

    shiny:
        image: rocker/shiny

    proxy:
        image: httpd
        volumes:
            - ./httpd.conf:/usr/local/apache2/conf/httpd.conf
            - ./proxy-html.conf:/usr/local/apache2/conf/extra/proxy-html.conf
        ports:
            - 80:80

The proxy-html.conf is taken from your config but with actual hostnames instead of localhost, since with docker-compose it will look as if RStudio Server and Shiny Server are running on different hosts:

#ProxyPreserveHost On
RewriteEngine on

RedirectMatch permanent ^/rstudio$ /rstudio/
RewriteCond %{HTTP:Upgrade} =websocket
RewriteRule /rstudio/(.*)     ws://rstudio:8787/$1  [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule /rstudio/(.*)     http://rstudio:8787/$1 [P,L]
ProxyPass /rstudio/ http://rstudio:8787/
ProxyPassReverse /rstudio/ http://rstudio:8787/
Header edit Location ^/ /rstudio/

RedirectMatch permanent ^/shiny$ /shiny/
RewriteCond %{HTTP:Upgrade} =websocket
RewriteRule /shiny/(.*) ws://shiny:3838/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule /shiny/(.*) http://shiny:3838/$1 [P,L]
ProxyPass /shiny/ http://shiny:3838/
ProxyPassReverse /shiny/ http://shiny:3838/

ProxyRequests Off

The httpd.conf is just the default config from the Docker image but with a bunch of modules enabled.

Using your original config with ProxyPreserveHost On I was able to reproduce your issue. Commenting this directive fixed it for me.

1 Like

It also appears to have fixed it for me.

In retrospect, that's probably the only line I didn't mess with in some way. I can't say for sure why it was on at all.

Thank you for your efforts!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.