【问题标题】:Nginx Redirects to Wrong URLNginx 重定向到错误的 URL
【发布时间】:2019-08-13 18:54:11
【问题描述】:

我有以下 Nginx 配置:

server {
   listen 8080 default_server;
   listen [::]:8080 default_server;
   ...

   error_page 401 = @login;
   location @login {
       return 302 https://$http_host/logon?continueURL=https://$http_host;
   }

   location /logon {
      proxy_redirect off;
      proxy_http_version 1.1;
      proxy_set_header Connection "";
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_pass http://${UPSTREAM_URL}$request_uri;
   }
...
}

在 Docker 文件中配置的 UPSTREAM_URL。 问题是当我有 401 错误时,Nginx 重定向到 https://localhost:8080/logon?continueURL=https://localhost:8080 而不是 http://${UPSTREAM_URL}$request_uri

Docker 镜像是nginx:alpine

我应该对我的配置进行哪些更改?

【问题讨论】:

    标签: nginx


    【解决方案1】:
    `location @login {
       return 302 https://$http_host/logon?continueURL=https://$http_host;
    

    } `这条线正在做重定向

    【讨论】:

    • 是的,我希望它重定向到location @login,然后重定向到location /logon
    • 我按照您的建议做了,它重定向到相同的 URL (localhost:8080/logon?continueURL=....) 但出现 504 HTTP 错误网关超时
    猜你喜欢
    • 1970-01-01
    • 2016-08-09
    • 1970-01-01
    • 2016-01-19
    • 2017-11-15
    • 2012-08-02
    • 2016-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多