SoFunction
Updated on 2025-04-07

Several solutions to several problems in requesting 404 after Nginx configuration

Request returns a 404 error, which may indeed be related toHostThe 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 itHostHeader to determine the processing logic or domain name resolution.

For example, if the backend serverneedHostThe header is its own domain name (i.e.), thenHostSet toThis may result in a 404 error because the server receives a domain name that it cannot recognize.

Solution:

Try toproxy_set_header HostChange to:

proxy_set_header Host ;

In this way, the backend server will receive the correct oneHostHeader information (i.e.) so that the request can be processed correctly.

2. Backend resource path issues:

ifHostThe header is set correctly, and still returns 404, which may be the backend server.It does not exist on it/user/tokenThis path. Can be accessed directly/user/tokento 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_passReserved/jx3/,for example:

proxy_pass /jx3/;

In this way, visit/jx3/us/tnIt 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!