【问题标题】:Shiny App Fails Without Trailing Slashes闪亮的应用程序在没有尾部斜杠的情况下失败
【发布时间】:2018-06-29 10:10:23
【问题描述】:

按照in this post 的指示,我正在代理后面运行一个闪亮的服务器。

带有斜杠http://yhat.io/shiny/faithful/ 的网址按预期工作。

但是,URL http://yhat.io/shiny/faithful(没有尾部斜杠)

被重定向到http://yhat.io/faithful/,它失败了,找不到 404。

这是我的nginx 配置,

location /shiny/ {
                rewrite ^/shiny/(.*)$ /$1 break;
                proxy_pass http://localhost:3838;
                proxy_redirect http://localhost:3838/ $scheme://$host/shiny/;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection $connection_upgrade;
                proxy_read_timeout 20d;
                proxy_buffering off;
        }

这是我的 nginx access.log

147.158.2.202 - - [20/Jan/2018:06:25:41 +0000] "GET /shiny/faithful/__sockjs__/n=9D3bkci4UbDJVuOKzw/866/05qfjneq/websocket HTTP/1.1" 101 19667 "-" "Mozilla/5.0 ...
147.158.2.202 - - [20/Jan/2018:06:25:39 +0000] "GET /faithful/ HTTP/1.1" 404 209 "-" "Mozilla/5.0 ..

我想知道为什么 rewrite 正则表达式不捕获尾部斜杠?没有尾部斜杠的 URL 被重定向到端口 80 而不是 Shiny 端口 3838。

我尝试了各种解决方案,包括

  • @Dean Attali 建议的rewrite ^(/shiny/[^/]+)$ $1/ permanent;
  • location ~ ^/shiny/?$ 启用正则表达式匹配
  • 注释掉location \

不幸的是,到目前为止没有任何效果。有人可以指出我的方向吗?

【问题讨论】:

    标签: nginx shiny reverse-proxy shiny-server proxypass


    【解决方案1】:

    我很抱歉,伙计们。经过大量修补,我得出结论@DeanAttali 的建议确实有效。

    rewrite ^(/shiny/[^/]+)$ $1/ permanent;
    

    问题在于 我的 Chrome 代理,这是一个孤立的问题。不幸的是,我仍然无法弄清楚背后的原因。

    如果将来有人遇到类似情况,我可以分享 2 个提示。

    1. 使用 User-Agent Spoofer 尝试各种浏览器类型来验证您的问题。
    2. 不要在浏览器上手动刷新,而是使用curl -L 来测试结果。

    在命令行上,

    $ curl -L yhat.io/shiny/faithful | head -n 10 
    
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100   194  100   194    0     0    194      0  0:00:01 --:--:--  0:00:01  1083
    100  2257  100  2257    0     0   2257      0  0:00:01 --:--:--  0:00:01  2257
    <!DOCTYPE html>
    <html>
    <head>
    
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
      <script type="application/shiny-singletons"></script>
      <script type="application/html-dependencies">json2[2014.02.04];jquery[1.12.4];shiny[1.0.5];ionrangeslider[2.1.6];strftime[0.9.2];bootstrap[3.3.7]</script>
    <script src="shared/json2-min.js"></script>
    <script src="shared/jquery.min.js"></script>
    <link href="shared/shiny.css" rel="stylesheet" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-04
      • 1970-01-01
      • 2022-09-28
      • 2017-06-14
      • 2018-04-08
      • 1970-01-01
      相关资源
      最近更新 更多