Request returns a 404 error, which may indeed be related toHost
The header is related, and it may also be a resource path problem of the backend server itself.
Error example:
location /jx3/ { rewrite ^/jx3/(.*)$ /$1 break; proxy_pass ; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }
Header settings problem:
In your current configuration,proxy_set_header Host $host;
The original host name of the client will be added (if so) Pass to the backend server. This may cause the backend server to fail to resolve the request correctly, especially if the backend server depends on it
Host
Header to determine the processing logic or domain name resolution.
For example, if the backend serverneed
Host
The header is its own domain name (i.e.), then
Host
Set toThis may result in a 404 error because the server receives a domain name that it cannot recognize.
Solution:
Try toproxy_set_header Host
Change to:
proxy_set_header Host ;
In this way, the backend server will receive the correct oneHost
Header information (i.e.) so that the request can be processed correctly.
2. Backend resource path issues:
ifHost
The header is set correctly, and still returns 404, which may be the backend server.It does not exist on it
/user/token
This path. Can be accessed directly/user/token
to verify whether the path exists.
Solution:
Check whether the backend server expects the request path format to change. For example, if the backend server needs to be retained/jx3/
Prefix, you can modify the rewrite rules or directly inproxy_pass
Reserved/jx3/
,for example:
proxy_pass /jx3/;
In this way, visit/jx3/us/tn
It will be proxyed as/jx3/us/tn
。
This is the article about several problems that require 404 after Nginx configuration. This is the end of this article. For more information about 404 after Nginx configuration, please search for my previous article or continue browsing the related articles below. I hope everyone will support me in the future!