【问题标题】:R Shiny app returning 404 when using NGINX as reverse proxy使用 NGINX 作为反向代理时,R Shiny 应用程序返回 404
【发布时间】:2021-11-22 03:31:19
【问题描述】:

我可以使用以下方式在本地运行 R Shiny 应用程序:

R -e "shiny::runExample('01_hello', host = '0.0.0.0', port = 3001L)

然后通过访问<ip-address>:3001 访问我本地网络上的任何位置。然后,我通常会在 NGINX 中添加一个 location 指令,如下所示:

  ...

  location /hello {
     proxy_pass http://localhost:3001;
   }

  ...

但是,虽然我可以访问 http://<ip-address>:3001,但当我尝试 http://<ip-address>/hello 时,我得到了 404。过去我已经这样做了很多次,并且相同的设置仍然适用于其他(非 Shiny)应用程序.如果其他人有类似的工作,我很想听听。

(请注意,我明确不是在谈论 Shiny Server——我有一个通过 NGINX 运行的 Shiny Server 实例没有问题)。

编辑:Markdown 在我的 cmets 中被内联,所以在这里添加。我应该注意到我的位置指令实际上如下所示并且仍然返回 404:

  location /hello {
    proxy_pass http://localhost:3001;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

不过,我没有将以下内容放在 http 块中,所以尝试了一下:

http {
  ...

  map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
  }  
  
  ...
}

无论哪种方式,我仍然收到 404 错误。多年来我一直在这样做(尽管应用程序通常在 Docker 容器中运行)而没有遇到任何问题,而这才刚刚开始发生。我想我会尝试在 Docker 容器中运行应用程序和 NGINX 的普通设置,这样我就可以排除我最近可能进行的其他配置更改。

【问题讨论】:

  • Shiny 的通讯地址是based on websockets。正如提到的herehereyou will also need to include code to correctly proxy websockets。 (这篇文章是关于 RStudio Server - 但我想这同样适用于独立应用程序)

标签: r nginx shiny


【解决方案1】:

好的,所以,这不起作用:

  location /hello {
    proxy_pass http://localhost:3001;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }

但确实如此:

  location /hello/ {
    proxy_pass http://localhost:3001/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }

我真的不清楚为什么,但我会好好阅读 NGINX 文档,我相信它会变得清楚。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-07
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    • 2021-08-25
    • 2021-05-22
    相关资源
    最近更新 更多