Reputation: 4203
I have an Nginx working as a upstream
upstream img_servers {
server localhost:8000;
server localhost:8001 backup;
}
I'm expecting the server listening on 80 would try the 2 servers in the upstream. When the file is not found, it should try the other one.
What I'm doing is
location ~ (jpg|jpeg|png|gif)$ {
proxy_pass http://img_servers;
proxy_next_upstream http_404;
}
However, the upstream server used the image_filter module, and when some image is not found, it always returns 415.
server {
listen 8000;
access_log logs/access_8000.log main;
error_page 415 =404 /empty.gif;
location ~ (sku_\d+(\d)(\d)(\d)_\d+)_(thumb|small)\.(jpg|png|jpeg|gif)$ {
alias /srv/http/media/$2/$3/$4/$1.$6;
image_filter resize 150 -;
image_filter_buffer 2M;
}
}
So when the code runs into the location, and the file doesn't exist, it returns 415 to the proxy. I'm expecting to return 404 so that proxy knows to try the next upstream server. According to the document of error_page I'm expecting to achieve this by:
error_page 415 =404 /empty.gif;
I don't know why this doesn't work for me. Any suggestions?
Upvotes: 0
Views: 3584
Reputation: 55
location ~ (sku_\d+(\d)(\d)(\d)_\d+)_(thumb|small)\.(jpg|png|jpeg|gif)$ {
error_page 415 = /empty;
alias /srv/http/media/$2/$3/$4/$1.$6;
image_filter resize 150 -;
image_filter_buffer 2M;
}
location = /empty
{
return 404;
}
Upvotes: 0
Reputation: 4203
Finally I found the solution. A little trick would resolve this issue:
error_page 404 =404 /empty.gif;
It seems like although nginx returned 415
to user, while internally it still thinks it's 404
. As I'm using the modified version of image filter, it might be the patch which leads to this issue. I'll edit my answer once I made sure.
Upvotes: 1