如何解决意外的 Nginx URL 尾部斜杠重写行为
我在单个文件中配置了以下(工作)位置指令(见评论)。
# syncthing.add-trailing-slash.conf
location ~ ^/syncthing$ {
# this is not as portable $scheme://$host$request_uri/,but can't figure out why it was rewriting https://shared-host/user-on-host/syncthing -> http://user-on-host.shared-host/syncthing/
# it was going from HTTPS to HTTP and a whole different domain...
return 302 https://shared-host/user-on-host/syncthing/;
}
# syncthing.reverse-proxy.conf
location ~ ^/syncthing($|./*) {
rewrite /syncthing/(.*) /$1 break; # this line is important to configuring the reverse proxy to listen on <host/username/service>
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 X-Forwarded-Proto $scheme;
proxy_pass http://localhost:10041;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
}
从第 4 行的注释中可以看出,我想在第 6 行使用 $scheme://$host$request_uri/
。但是,当我使用该配置时,导航到 https://shared-host/user-on-host/syncthing
的结果将我重定向到 {{ 1}}(如第 4 行的注释所示)。
我的目标是避免管理我自己的 TLS 证书。我共享的服务器已经有一个,所以我想使用它。我还想让第一个 location 指令可移植,这样我就不需要为每个服务都一个新的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。