Search code examples
rnginxshinyshiny-server

Shiny Server - problem hosting an additional app


I currently have a live website that hosts one app at the moment through shiny server. I've been trying for some time to figure out how to host an additional app as an extension of the domain. If my website is "www.mywebsite.com", which hosts the main app, I want to host another app at "www.mywebsite.com/SecondApp". I've read through all of the documentation that I've found, and it appears this should be possible by altering the shiny-server.conf file in the /etc/shiny-server directory. Per section 2.2.2 Location in the Shiny Server Admin Guide it would appear that updating the configuration file as so should achieve this:

server {
...
  location /SecondApp {
  app_dir /srv/shiny-server/SecondApp
  }
...
}

I've added the respective ui.R and server.R scripts to the /srv/shiny-server/SecondApp directory, and I am able to run this locally in my browser browser at

MYIP:3838/SecondApp/ 

But when I update the shiny-server.conf script and restart shiny server, "www.mywebsite.com/SecondApp" returns a blank screen that shows "Not Found". I haven't tried setting up a new port for this app, but from everything I've seen in the documentation and various github scripts, it seems this configuration should work. What am I missing? My full configuration file looks like:

# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;

# Define a server that listens on port 3838
server {
  listen 3838;

    log_dir /var/log/shiny-server;

  # Add extension
  location /SecondApp {
    app_dir /srv/shiny-server/SecondApp;
  }

  # Define a location at the base URL
  location / {

    # Host the directory of Shiny Apps stored in this directory
    site_dir /srv/shiny-server;

    # Log all Shiny output to files in this directory
    #log_dir /var/log/shiny-server;

    # When a user visits the base URL rather than a particular application,
    # an index of the applications available in this directory will be shown.

    directory_index on;
  }
}

Is the issue here the port? It appears 3838 is the default shiny server port, and from what I've seen it appears others sometimes update this to run through its own port. But as I mentioned, the current site I run works completely fine. I've also tried updating the nginx configuration file in the /etc/nginx/sites-enabled directory by adding an additional location as so, but this doesn't help:

server {
...
location /SecondApp {
    proxy_pass http://MYIP:3838/SecondApp/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }
...
}

Unless this has to do with my actual domain, I'm at a loss. Any ideas? Thanks!


Solution

  • If you configure nginx config in /etc/nginx/sites-enabled/ to proxy all traffic to port 3838 like so:

    location / {
             proxy_pass http://127.0.0.1:3838/;
             proxy_http_version 1.1;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection "upgrade";
    }
    

    You can then get the shiny-server config to control what apps are served at what extension. The config below should work for you.

    # Instruct Shiny Server to run applications as the user "shiny"
    run_as shiny;
    
    # Define a server that listens on port 3838
    server {
      listen 3838;
    
      # Define a location at the base URL
      location / {
    
        # Host your main app at the base URL
        app_dir /srv/shiny-server/MainApp;
    
        # Log all Shiny output to files in this directory
        log_dir /var/log/shiny-server;
    
        # define a location within the base location
        # to serve your second app
        location /SecondApp {
          app_dir /srv/shiny-server/SecondApp;
        }
      }
    
    }
    

    Remember to restart nginx and shiny-server for changes to take effect.

    sudo systemctl restart nginx
    sudo systemctl restart shiny-server