在Nginx中根据请求的url文件扩展名有条件地提供404文件?

我想知道,如果我可以有条件地提供一个特定的文件作为404页面基于请求的URL,或内容types/ MIMEtypes请求。

我猜测的是:

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

我不太熟悉NGINX 404 / url重写。

目前,我有:

 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; } } 

不完全是一个好看的configuration,但它应该工作。

 error_page 404 = @missing; location @missing { if ($request_filename ~* [gif|jpg|png]$){ rewrite ^ /404.gif; } if ($request_filename !~* [gif|jpg|png]$){ rewrite ^ /404.html; } }