大网数据广告活动
服务器运维问答

Nginx 302 redirect loop debugging

· 52CE 我爱测

I have more than 50+ location match directives in my web application nginx file. after making some changes, i am stuck with a 302 redirect loop on one location directive called /login. it keep redirecting to 302 /login and never …

问题原文

原帖链接 · Farhan · CC BY-SA 3.0

I have more than 50+ location match directives in my web application nginx file. after making some changes, i am stuck with a 302 redirect loop on one location directive called /login. it keep redirecting to 302 /login and never gets out. is there any way in nginx directives that i can setup a breakpoint, a log, that from which location directives the request passes? so i get an idea that which is the faulty redirect or location source?

i dont think the debug log gives this information.

In short, what is the best way to Trace the request precisely and in very detailed way among whole configuration

已采纳解答

原帖链接 · cnst · CC BY-SA 3.0

Why do you have 50+ location match directives? The correct solution might be to use the map directive instead.

The correct way to debug the changes having unintended consequences is to do revision control of your changes:

  • If a whole bunch of changes were made, and never tested in-between, then you can use something like git-bisect to find out the offending directive.

  • If you already know the offending change, then carefully examining each part should reveal the issue.

However, based on the hostname from your screenshot, and examining the response of your server:

curl -v -k https://www.groupsitedev.com/login | & sed -E "s#^#`printf \\t`#g"
…
< HTTP/1.1 302 Moved Temporarily
< Server: nginx/1.13.3
< Date: Sun, 27 Aug 2017 02:21:44 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Runtime: 2
< Location: https://www.groupsitedev.com/login
< Cache-Control: no-cache
< Set-Cookie: _session_id=882afb51754b1cd5deef94cb65457625; domain=.groupsitedev.com; path=/
< 
<html><body>You are being <a href="https://www.groupsitedev.com/login">redirected</a>.</body></html>

…, reveals that this issue is likely not related to nginx, and is likely performed upstream:

  • it's very unlikely that you've modified the default nginx 302 handler to provide text like <html><body>You are being <a href="https://www.groupsitedev.com/login">redirected</a>.</body></html>, which is not the default; and a redirect from an inefficient upstream is much more likely (nginx wouldn't provide such custom text (with a hyperlink) because it's inefficient to copy the URL multiple times like that, into a web-page that no modern browser will ever show up anyway)

  • it's very unlikely that you've configured nginx to issue session cookies, all by itself; a cookie from your upstream is much more likely.

Thus, in summary, there is nothing to debug in nginx — the redirect is clearly coming from your upstream, which you've revealed to us nothing about.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-08-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。