Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display default image when missing file in nginx

Tags:

nginx

We have various pictures associated with items on our site but not for all of them. To this end we would like to display the contents of 'blank.jpg' if a given image is not found.

To this end we have the nginx config like this

location /static/images/ {
    root /blah_blah_blah/pictures/;
    error_page 404 blank.jpg;
    break;
}

The problems with this is that this takes /static/images/fred.jpg and redirects to /static/images/blank.jpg when what we want is to simply display the contents of blank.jpg whilst keeping the /static/images/fred.jpg url

It also seems to go into a redirect loop occasionally.

like image 385
Peter Hickman Avatar asked Nov 01 '22 07:11

Peter Hickman


1 Answers

Not sure if you still need it 10 month later but this looks like what you were looking for: https://serverfault.com/questions/562269/redirect-missing-images-in-a-specific-directory

like image 112
yefrem Avatar answered Nov 09 '22 07:11

yefrem