Answer the question
In order to leave comments, you need to log in
How to detect 404 error in nginx on port 80 and redirect request to port 8080, which apache server is listening on?
Guys, see the situation without nginx:
1. The client requested a file, say image.jpg, which does not physically exist, apache processes the request, realizing that the file does not physically exist, redirects the request to the php side, which in turn creates this file.
2. The client again requested a file, image.jpg which physically exists (see point 1), therefore it is immediately given to the client.
And now look at the situation with nginx:
1. The client requested a file, say image.jpg, which does not physically exist, nginx notifies the client of a 404 error.
Actually, the question is how to implement the correct scheme in the nginx settings of this kind:
1. The client requested a non-existent file, nginx processes the request and redirects it to apache (8080 port).
2. Apache, having processed the request, acts according to the scheme described at the very beginning (pp. 1.2 at the very beginning).
What do you advise? Thank you.
PS If in one line: How to detect a 404 error in nginx on port 80 and redirect the request to port 8080, which is listening to the apache server.
Answer the question
In order to leave comments, you need to log in
nginx has a try_files directive for this.
Why do you need apache in this chain? Is it possible to send such requests directly to php-fpm?
location{
....
error_page 404 = /404.php;
}
error_page 404 = @fallback;
location / { ...; }
location ~* ^.+\.(jpg|jpeg|gif|...) { ...; }
location @fallback {
proxy_pass http://127.0.0.1:81;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
If there are not many such requests, then you can enable caching of 200 responses in nginx, and hang up request processing in PHP. But this method can "eat" RAM.
error_page 404 = @fallback;
#--------------All 404s are sent to Apache for processing----------------------------- --
location @fallback {
proxy_pass http://$host:82;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question