如何将nginx位置添加回302重定向响应位置

问题描述 投票:0回答:1

我有一个在nginx服务器后面运行的django-cms应用程序。我正在使用proxy_pass将流量发送到cms应用程序。我使用的是位置/ django-cms,所以当我转到https://nginxserver/django-cms时,它实际上可以正常工作并将流量发送到CMS服务器,但是CMS应用程序将发回302响应,并且该响应包含Location:en /,因此浏览器尝试按https://nginxserver/en/代替f https://nginxserver/django-cms/en。这显然会导致404错误。如何确保CMS服务器所需的所有内容均显示为https://nginxserver/django-cms/

这里是nginx.conf文件中的相关部分。

location /django-cms {
    auth_request /request_validate;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://10.0.2.29:8000;
}
nginx nginx-reverse-proxy
1个回答
0
投票
location /django-cms {
  proxy_pass http://10.0.2.29:8000;
  proxy_redirect ~^/(.*) scheme://$http_host/django-cms/$1;
}

代理重定向说明可能会对您有所帮助,您可以尝试吗?它将django-cms添加到后端(cms)给您的任何重定向中。

这是我第一次使用它,但是看起来就像在nginx文档中那样使用它。

((发现了另一个与您有相同问题的问题):

Intercepting backend 301/302 redirects (proxy_pass) and rewriting to another location block possible?

如果您也想检查它:D

© www.soinside.com 2019 - 2024. All rights reserved.