问题原文
原帖链接 · 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-bisectto 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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
