• Welcome to LiuJason's Blog!

使用Nginx来反代Shinyapp 实现子路径访问

Linux笔记 Jason 4 years ago (2020-02-15) 885 Views 0 Comments QR code of this page
文章目录[隐藏]

前言

汤老板来问,我就整理一下吧。这里面有几个坑需要注意的:

  • Shiny必须使用Nginx的Websocket插件,所以需要在Nginx里面打开,1.6以上版本都是自带的,直接使用即可。
  • Shiny的默认端口是3838,如果是引用非本地的shiny服务的话,防火墙注意开启
  • 我安装下来发现,在有IPv6的条件下,Shiny会优先监听IPv6,因此需要修改/etc/shiny-server/shiny-server.conf中的监听端口,添加0.0.0.0以监听IPv4(改为::可以强制监听IPv6):
-------
# Define a server that listens on port 3838
server {
  listen 3838 0.0.0.0;
-------

Nginx规则

location /shiny/
{
    if ($request_uri ~* "(php|jsp|cgi|asp|aspx)")
                {
                         expires 0;
                }
    proxy_pass http://shiny的ip:3838;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    add_header X-Cache $upstream_cache_status;
    add_header Cache-Control no-cache;
    expires 0;
}

This article is under CC BY-NC-SA 4.0 license.
Please quote the original link:https://www.liujason.com/article/529.html
Like (1)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址