通过 nginx 将端口 80 路由到 shiny-server

通过 nginx 将端口 80 路由到 shiny-server

我认为我已经完成了 90% 的操作,但输入 domain.net 会带我进入“欢迎使用 nginx”登陆界面,而不是 shiny-server(位于 3838)。

Nginx config file:

    server {
            listen 80 default_server;
            listen [::]:80 default_server;

            # SSL configuration
            #
            # listen 443 ssl default_server;
            # listen [::]:443 ssl default_server;

            root /srv/shiny-server/;

            # Add index.php to the list if you are using PHP
            index index.html index.htm index.nginx-debian.html;

            server_name _;

            location / {
            proxy_pass http://127.0.0.1:3838/;
            proxy_redirect http://127.0.0.1:3838/ $scheme://$host/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
         }
    }


Shiny-server config file:

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

$sudo netstat -nlp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1159/nginx -g daemo
tcp6       0      0 :::80                   :::*                    LISTEN      1159/nginx -g daemo

$curl http://127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

更新:我将端口 80 添加到我的 aws 安全配置文件中,现在我甚至无法在 :3838 处加载 shiny-server,更糟糕的是,当我关闭 nginx 时,我仍然无法通过 3838 访问。添加这个单个端口怎么会毁掉我的整个设置呢?

答案1

您需要检查 shiny-server 是否正在运行并监听 TCP 端口 3838。使用此命令

netstat -antp | grep 3838

相关内容