I have Shiny Server working ok on my URL, but am having trouble accessing the apps from a secure connection.
I used Certbot to install the SSL certificate, and followed Step 3 in this guide to set up the reverse proxy.
Entering my URL into a browser now brings me directly to the https site with the default "Welcome to Shiny Server!" page (ie my server ip at port 3838). All the text is there ("If you're seeing this page, that means Shiny Server is installed...etc").
The problem is that the sample apps are not showing - they both return '404 Not Found'.
My nginx server file (nginx/sites-available/shiny-server) looks like this:
server {
listen 80 ;
listen [::]:80 ;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name myURL.com; # managed by Certbot
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/myURL.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/myURL.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
proxy_pass http://server.ip.address:3838/;
proxy_redirect http://server.ip.address:3838/ https://$host/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
}
}
I've tried modifying the location
section numerous ways based on other answers on Stack Overflow and elsewhere (eg here) but nothing resolved the issue.
I added the following the bottom of nginx.conf
:
# Map proxy settings for RStudio
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
and my shiny-server.conf
looks like this (default):
# 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;
}
}
The apps work fine if I go to http://my.server.ip:3838 or http://myURL.com:3838, but not if I go to https://myURL.com or http://myURL.com (Shiny Server page loads in both cases but the sample apps are 404).
Okay, it turns out the line try_files $uri $uri/ =404;
was causing the problem. Commented that out and all is well.