【问题标题】:Shiny Server - problem hosting an additional appShiny Server - 托管其他应用程序的问题
【发布时间】:2019-04-08 14:12:33
【问题描述】:

我目前有一个实时网站,目前通过闪亮的服务器托管一个应用程序。我一直在尝试弄清楚如何托管一个额外的应用程序作为域的扩展。如果我的网站是托管主应用程序的“www.mywebsite.com”,我想在“www.mywebsite.com/SecondApp”托管另一个应用程序。我已经阅读了我找到的所有文档,看来这应该可以通过更改 /etc/shiny-server 目录中的 shiny-server.conf 文件来实现。根据Shiny Server Admin Guide 中的第 2.2.2 节位置,似乎更新配置文件应该实现这一点:

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

我已将相应的 ui.R 和 server.R 脚本添加到 /srv/shiny-server/SecondApp 目录,我可以在浏览器浏览器中本地运行它

MYIP:3838/SecondApp/ 

但是当我更新shiny-server.conf 脚本并重新启动闪亮服务器时,“www.mywebsite.com/SecondApp”会返回一个显示“未找到”的空白屏幕。我还没有尝试为这个应用程序设置一个新端口,但是从我在文档和各种 github 脚本中看到的所有内容来看,这个配置似乎应该可以工作。我错过了什么?我的完整配置文件如下所示:

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

这里的问题是端口吗?看起来 3838 是默认的闪亮服务器端口,据我所见,其他人有时会更新它以通过自己的端口运行。但正如我所提到的,我运行的当前站点运行良好。我还尝试通过添加一个额外的位置来更新 /etc/nginx/sites-enabled 目录中的 nginx 配置文件,但这没有帮助:

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

除非这与我的实际域有关,否则我很茫然。有任何想法吗?谢谢!

【问题讨论】:

  • AFAIK 不可能在//secondApp 拥有应用程序,因为这些位置是嵌套的。请改用/firstApp/secondApp。如果你真的需要一个嵌套结构,你可以让它与符号链接一起使用

标签: r nginx shiny shiny-server


【解决方案1】:

如果您在/etc/nginx/sites-enabled/ 中配置 nginx 配置以将所有流量代理到端口 3838,如下所示:

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

然后,您可以获取 shiny-server 配置来控制在什么扩展程序上提供哪些应用程序。下面的配置应该适合你。

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

}

记得重启 nginx 和 shiny-server 以使更改生效。

sudo systemctl restart nginx
sudo systemctl restart shiny-server

【讨论】:

  • 哇,效果很好!非常感谢,这正是我想要的!
猜你喜欢
  • 2017-02-13
  • 2018-05-23
  • 2018-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-07
  • 2019-02-04
  • 1970-01-01
相关资源
最近更新 更多