Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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;
   }
}
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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;
  }
}
share|improve this answer
    
nice. Thank you. –  Louis Aug 27 '10 at 18:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.