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

我有一个在nginx服务器后面运行的django-cms应用程序。我正在使用proxy_pass将流量发送到cms应用程序。我使用的是位置/ django-cms,因此当我转到https://nginxserver/django-cms时,它实际上可以正常工作并将流量发送到CMS服务器,但是CMS应用程序将发回302响应,并且响应包含Location:en /,因此浏览器会尝试点击https://nginxserver/en/而不是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;
}
tangjw08 回答:如何将Nginx位置添加回302重定向响应位置

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

本文链接:https://www.f2er.com/3061288.html

大家都在问