1

I would like to know if I can conditionally serve a specific file as a 404 page based on the request url, or the content-type/mime-type requested.

I'm guess something along the lines of:

if url_extention == (gif|jpg|png):
    /404.gif
else:
    /404.html

I am not too familiar with NGINX 404/url rewrites.

At the moment, I have:

server
{

   listen 80;
   server_name static.example.com;
   access_log off;
   location / {
       root /warehouse/web/static/static.example.com;
       expires 3d;
       error_page 404 = /404.gif;
   }

   location /404.gif {
       root /warehouse/web/static/404;
   }
}
Louis
  • 155
  • 1
  • 6

1 Answers1

1

Not exactly a nice looking configuration but it should work.

error_page 404 = @missing;

location @missing {
  if ($request_filename ~* [gif|jpg|png]$){
    rewrite ^ /404.gif;
  }
  if ($request_filename !~* [gif|jpg|png]$){
    rewrite ^ /404.html;
  }
}
Martin Fjordvald
  • 7,589
  • 1
  • 28
  • 35