闪亮服务器-托管其他应用程序时出现问题

时间:2018-11-05 08:21:35

标签: r nginx shiny shiny-server

我目前有一个在线网站,目前通过闪亮的服务器托管一个应用程序。我已经尝试了一段时间,以找出如何托管其他应用程序作为域的扩展。如果我的网站是托管主要应用程序的“ www.mywebsite.com”,我想在“ www.mywebsite.com/SecondApp”托管另一个应用程序。我已经阅读了所有找到的文档,并且看来应该可以通过更改/ etc / shiny-server目录中的shiny-server.conf文件来实现。根据{{​​3}}中第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";
  }
...
}

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

1 个答案:

答案 0 :(得分:2)

如果您在/etc/nginx/sites-enabled/中配置nginx config来将所有流量代理到端口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";
}

然后,您可以获取“闪亮服务器”配置,以控制在哪个扩展名上提供哪些应用程序。以下配置应该适合您。

# 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
相关问题