Serve RStudio from example.com/rstudio with an Apache proxy

rstudioserver

#1

I tried to follow the instructions for serving RStudio from a custom path (e.g. example.com/rstudio), but they didn’t work for me.

The instructions: https://support.rstudio.com/hc/en-us/articles/200552326-Configuring-the-Server/

Apache configuration:

  RewriteEngine on
  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/
  ProxyRequests Off

When I visit example.com/rstudio I get redirected to example.com/auth-sign-in and see:

Not Found
The requested URL /auth-sign-in was not found on this server.

If I add two more lines for the auth-sign-in URL like this:

ProxyPass        /auth-sign-in   http://localhost:8787/auth-sign-in
ProxyPassReverse /auth-sign-in   http://localhost:8787/auth-sign-in

Then I see a login screen like this (notice the image does not load):

RStudio_Sign_In

The image does not load because it’s being requested from example.com/images/rstudio.png

Finally, when I try to login with an existing user/pass on my system, I get Error: Not Found.

I guess the instructions should be updated. My guess is that serving from a custom path like example.com/rstudio is more difficult to set up than serving from a naked domain like example.com.

I’d appreciate any tips!


#2

I’m hoping to have a chance to give this a shot later and see if I can reproduce. In the meantime, it can be helpful to enable the Chrome / Firefox developer tools and look at the “network” tab to see where you are being routed:

You can also do some cool stuff with curl - i.e. curl -i http://my.url will show the response header, which can be useful for determining what is going on with a proxy.


#3

I can reproduce on Ubuntu 16.04 and apache2. Setting up Shiny Server and RStudio Servers on subpaths is notoriously difficult. My config so far:

# /etc/apache2/sites-available/shiny.conf                                                                                                                                                                                                                                                                                                                                                    
   RewriteEngine on                                                                                                                                                                                                 
   RewriteCond %{HTTP:Upgrade} =websocket                                                                                                                                                                           
   RewriteRule /shiny/(.*) ws://127.0.0.1:3838/public/$1 [P,L]                                                                                                                                                      
   RewriteCond %{HTTP:Upgrade} !=websocket                                                                                                                                                                          
   RewriteRule /shiny/(.*) http://127.0.0.1:3838/public/$1 [P,L]                                                                                                                                                    
                                                                                                                                                                                                                    
   #ProxyPreserveHost On                                                                                                                                                                                            
   ProxyPass /shiny/ http://localhost:3838/public/                                                                                                                                                                  
   ProxyPassReverse /shiny/ http://localhost:3838/public/                                                                                                                                                           
   ProxyRequests Off                                                                                                                                                                                                
                                                                                                                                                                                                                    
   # redirect to add trailling slash                                                                                                                                                                                
   RedirectMatch permanent ^/shiny$ /shiny/    

# /etc/apache2/sites-available/rstudio.conf 
RewriteEngine on                                                                                                                                                                                                  
  RewriteCond %{HTTP:Upgrade} =websocket                                                                                                                                                                            
  RewriteRule /rstudio/(.*) ws://localhost:8787/$1 [P,L]                                                                                                                                                            
  RewriteCond %{HTTP:Upgrade} !=websocket                                                                                                                                                                           
  RewriteRule /rstudio/(.*) http://localhost:8787/$1 [P,L]                                                                                                                                                          
                                                                                                                                                                                                                    
  ProxyPreserveHost On                                                                                                                                                                                              
  ProxyPass /rstudio/ http://localhost:8787/                                                                                                                                                                        
  ProxyPassReverse /rstudio/ http://localhost:8787/                                                                                                                                                                 
  ProxyRequests Off                                                                                                                                                                                                 
                                                                                                                                                                                                                    
  # redirect to add trailling slash                                                                                                                                                                                 
  RedirectMatch permanent ^/rstudio$ /rstudio/