The 404 problem of nginx reverse proxy

Time:2021-4-17

When configuring nginx’s reverse proxy on the pagoda panel, we encountered a 404 problem. After checking the information, we found a solution. This problem is generally that the proxy is not configured correctly_ I’m rather lazy, so I’ll give you a direct answer

Configuring proxy in nginx_ When passing reverse proxy, when /, which is equivalent to the absolute root path, is added to the following URL, nginx will not give the proxy the part of the matching path in the location; if there is no /, it will also give the proxy the part of the matching path.

Example:

Access path:

/pss/bill.html
1. When nginx configuration file proxy_ When the URL after pass has a ‘/’:
location /pss/ {
    proxy_pass http://127.0.0.1:18081/;
} 

The path from proxy to back end is as follows:http://127.0.0.1:18081/bill.html, omitting the matched / PSS / path;

2. When nginx configuration file proxy_ When the URL after pass does not have a ‘/’:
location /pss/ {
    proxy_pass http://127.0.0.1:18081;
}

The path from proxy to back end is as follows:http://127.0.0.1:18081/pss/bill.htmlThe reverse proxy is performed together with the matched / PSS / path;

Author: Han Ling
Link:https://www.zhihu.com/questio…
Source: Zhihu
The copyright belongs to the author. For commercial reprint, please contact the author for authorization. For non-commercial reprint, please indicate the source.