具有 nginx 和 https 的闪亮服务器:404 用于应用程序

Shiny server with nginx and https : 404 for apps

我的 URL 上的 Shiny Server 工作正常,但无法通过安全连接访问应用程序。

我使用 Certbot 安装了 SSL 证书,并按照 this guide 中的步骤 3 设置了反向代理。

在浏览器中输入我的 URL 现在可以直接进入带有默认 "Welcome to Shiny Server!" 页面的 https 站点(即我的服务器 ip 在端口 3838)。所有的文字都在那里 ("If you're seeing this page, that means Shiny Server is installed...etc")。

问题是示例应用程序未显示 - 它们都 return“404 未找到”。

我的 nginx 服务器文件 (nginx/sites-available/shiny-server) 如下所示:

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

我尝试根据 Stack Overflow 和其他地方的其他答案(例如 here)以多种方式修改 location 部分,但没有解决问题。

我在 nginx.conf 的底部添加了以下内容:

# Map proxy settings for RStudio
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

我的 shiny-server.conf 看起来像这样(默认):

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

如果我转到 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 页面,但示例应用程序是 404)。

好的,原来是 try_files $uri $uri/ =404; 行导致了问题。评论说出来,一切都很好。