nginx reverse proxy infinite loop encountered proxy_pass

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/bowei026/article/details/90417914

In order to solve the problem of cross-domain interface calls, cross-domain use nginx reverse proxy to solve the most simple code to indicate the following:

server{
    server www.demo.com;

    location /api/ {
        proxy_pass http://hello.test.com/api/;
    }
}

But running nginx, after the interface to access the proxy, found particularly slow response, 413 Request Entity Too Large such a prompt appears after some time.

Nginx and then view the log, the log request header found in the emergence of a large number of duplicate ip address, the request seems to be the emergence of an infinite loop, and then there was the request is too large for tips.

That probably locate the problem, search for the keyword "nginx proxy_pass cycle" to find the cause and solution to the problem:

server{
    server www.demo.com;

    location /api/ {
        proxy_set_header Host "hello.test.com";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://hello.test.com/api/;
    }
}

Is the need to modify the request header, do not let www.demo.com to the request header proxy_pass in, otherwise they will again call the reverse proxy, causes the proxy endless loop.

Host write directly proxy_set_header the dead to solve the problem.

This concludes this article, it may be more concerned about the number of public and personal micro signal:

Guess you like

Origin blog.csdn.net/bowei026/article/details/90417914