Serving a default image with nginx

Posted by ustun on Server Fault See other posts from Server Fault or by ustun
Published on 2012-06-03T14:33:52Z Indexed on 2012/06/03 16:42 UTC
Read the original article Hit count: 177

Filed under:

I have the following configuration in nginx:

  location /static/ {
       root /srv/kose/;
       expires 2w;
       access_log off;
 }


 location / {
    proxy_pass http://127.0.0.1:8089;

}

If a file is not found in /static/, I want to serve a default image, and not proxy_pass to 8089. Currently, it looks for the file in the root for static, if it cannot find it, it tries the proxy.

I have tried the following, but it doesn't work. How can I tell nginx to serve the default image? I have also tried try_files to no avail.

  location /static/ {
       root /srv/kose/;
       expires 2w;
       access_log off;
       error_page 404 /srv/static/defaultimage.jpg;
 }


 location / {
    proxy_pass http://127.0.0.1:8089;

}

© Server Fault or respective owner

Related posts about nginx