I’m using nginx v1.6.2 to serve both dynamic nodeJS and static file content for a web-based application.
Within a certain location (that happens to be serving static png files only), I want any not found image requests to return one specific placeholder image, “blank.png”.
For example, the file at path
%nginxroot%/html/tiles/sectionals/0/0/0.png does exist, so the URL http://myhost/tiles/sectionals/0/0/0.png should return the image file requested. But the file at path
%nginxroot%/html/tiles/sectionals/0/0/99.png does not exist, so request http://myhost/tiles/sectionals/0/0/99.png should return the file at
Here is my (edited for brevity) nginx.conf:
The behavior I’m seeing with this configuration is that if the file exists, it works, if the file doesn’t exist the browser tells me I have a redirect loop and the console shows
GET http://myhost/tiles/sectionals/0/0/blank.png net::ERR_TOO_MANY_REDIRECTS.
I’ve tried solutions that might account for a pathing issue, like error_page 404 = ./blank.png, turing off or omitting proxy_intercept_errors, putting a blank.png in both html and tiles directories, and I can’t seem to get it to work – with one exception, and that is to put a blank.png in every single directory where an image might be requested. That seems like a silly workaround however.
So I understand that nginx isn’t able to find blank.png and as such is redirecting infinitely (or beyond some threshold), but what should the .conf file have for that location and/or where should the blank.png be located?
You need to specify the absolute path to the document you want to serve. Otherwise it is treated as a path relative to the URL that was originally requested.
error_page 404 = /tiles/blank.png;
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.