【发布时间】:2020-08-03 15:47:14
【问题描述】:
我遇到了以下问题,我希望能够从带有斜杠的主网站访问代理传递的位置(托管 docker 容器中的 React/NextJs webApp)和 没有尾部斜杠。
目前,当我点击:
http://my-website.com/test # 这行得通
但是当我击中时:
http://my-website.com/test/ # 失败并返回 404
我希望能够同时访问这两个网址。我错过了什么?
### Default Server ###
server {
listen 80;
root /usr/site;
if ($http_x_forwarded_proto = "http") {
return 301 https://$host$request_uri;
}
location ~/test(.*)$ {
set $upstream_endpoint http://$docker_container_url;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_pass $upstream_endpoint$1/;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
【问题讨论】:
-
试试这个:
location /test {定义严格的路由没有 - tilda(正则表达式) -
我也无法理解您想要实现的目标。您正在重定向到 https 版本,但在 /test 您正在请求上游的 http 版本,它将再次重定向(因为 http => https)
-
my-website.com 的配置在哪里?
-
my-website.com 是一个用 React 编写的 NextJS 配置应用程序。该应用使用“/test”的 AssetPrefix。
-
这个 nginx 配置是我家网站上的反向代理设置,我正在尝试连接到作为 upstream_endpoint 传入的 docker 容器。我试图让场景更简单一些,因为我相信它与斜杠问题无关。
标签: nginx nginx-reverse-proxy nginx-config