Shiny-server crashes when called via domain name / port 80


#1

I'm running Shiny Server on an AWS EC2 (Ubuntu 16.4), and trying to configure an Apache2 server reverse proxy to serve port 3838 to the website's /apps sub-folder. I've opened port 3838 in the AWS security group, as well as ufw on the EC2. When I call the IP directly (http://x.x.x.x:3838/) it works fine, as when I call the EC2's default public DNS - http://ec2-x-x-x-x.region.compute.amazonaws.com:3838/.

But I've also set up a domain mydomain with a DNS provider and set to web forward from mydomain to the IP. When I call the root I get the correct apache page. When I call /apps/ the Welcome to Shiny Server! page comes through but the embedded demo shiny apps crash. Checking the log directory reveals:

-rw-r-----  1 shiny shiny    37 Apr 10 12:58 hello-shiny-20180410-125811-42266.log
-rw-r-----  1 shiny shiny    37 Apr 10 12:58 rmd-shiny-20180410-125811-42875.log

Weirdly, these disappear on their own after a moment. But reading as su reveals:

root@ip-x.x.x.x:/var/log/shiny-server# cat hello-shiny-20180410-125924-38902.log
Listening on http://127.0.0.1:38902

[N.B. I previously said this was Permission denied but I realised that was the response to the cat call!]

Can anyone please help to identify why this is failing. I've spent hours trawling questions around this and nothing works.

My /etc/apache2/sites-available/000-default.conf file <VirtualHost *:80> clause contains:

	ProxyPass /apps/ http://0.0.0.0:3838/
	ProxyPassReverse /apps/ http://0.0.0.0:3838/

/etc/shiny-server/shiny-server.conf 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;

  # 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;
  }
}

#2

I think what the error is saying is that Shiny doesn't have permission to save its log in the default location (or location specified in the Shiny-Server configuration file, if you've added one.) Why it would have permission in one case but not the other is the puzzle.

If you give up, I've written information on how to do this on AWS Lightsail (EC2 simplifed) with nginx instead of Apache as the server.. Start at the bottom post on that page and then go upward.


#3

Thanks open-meta. Actually it's the response to the cat call! I've edited the question to reflect. But I think it is definitely a user/permissions issue.


#4

If I understand your issue right, you are talking about setting up an Apache proxy that does not seem to be working correctly. I would be curious if the following article helps:

First, I would check to be sure accessing the apps on the desired port my-domain.org:3838 works as expected. i.e. in this way you test shiny server without the proxy. Then you need to get the proxy to work and access at my-domain.org/apps/. Once the proxy is working, you technically will not need to "open" port 3838 to outside traffic. The internal proxy takes care of routing from 80 to 3838. Of course, you can leave 3838 open if you like, as well.

One last tidbit - it is possible to make shiny server listen directly on port 80 if you like. I.e. you do not need to have a proxy to get things listening on port 80. That's your call, though! http://docs.rstudio.com/shiny-server/#host-a-directory-of-applications-1


#5

Yes I tried to implement those instructions, and apache crashed on restart. I'll try again and post response in a sec.

http://mydomain:3838 fails (empty response). I understood I'd need to implement a separate apache listener for that. But as I mentioned, http://[ip_address]:3838 does respond properly, as well as http://[aws_default_ec2_dns]:3838, so I know it works without the proxy.

Yes I need to run other stuff on the server so unfortunately listening on port 80 isn't possible.


#6

OK so re-running through the official guide, I spotted it failed because:

Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

This led me to discover that mod_rewrite was deactivated, despite that activating this is in my setup script. So a simple sudo a2enmod rewrite has fixed the issue, and all now works fine.

Thanks for help.


#7

So glad you got to the bottom of it!


#8

If your question's been answered/resolved, would you mind choosing a solution (even if, as it seems in this case, it's your own response? (see FAQ below for how)

It makes it a bit easier to visually navigate the site and see which questions still need help.

Thanks very much!