Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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):

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

At the moment, I have:


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

   location /404.gif {
       root /warehouse/web/static/404;
share|improve this question
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


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.