【发布时间】: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