Nginx静态文件排除一个或一些文件扩展名

我通过nginx提供了一个静态网站。

location ~* \.(avi|bin|bmp|dmg|doc|docx|dpkg|exe|flv|gif|htm|html|ico|ics|img|jpeg|jpg|m2a|m2v|mov|mp3|mp4|mpeg|mpg|msi|pdf|pkg|png|ppt|pptx|ps|rar|rss|rtf|swf|tif|tiff|txt|wmv|xhtml|xls|xml|zip)$ { root /var/www/html1; access_log off; expires 1d; } 

我的目标是排除像http://connect1.webinar.ru/converter/task/请求。 完整视图就像http://mydomain.tld/converter/task/setComplete/fid/34330/fn/7c2cfed32ec2eef6788e728fa46f7a80.ppt.swf 。 尽pipe这些URL以这种格式结尾,但它们并不是静态的,而是伪造的脚本请求,所以我遇到了一些问题。

做这个的最好方式是什么? 如何添加这个URL的排除或者我可以从这个Nginx位置的列表中排除特定的文件exptension(.ppt.swf,pptx.swf)?

谢谢。

 location ~* \.(?:avi|bin|bmp| ... |(?<!\.pptx\.|\.ppt\.)swf)$ { root /var/www/html1; access_log off; expires 1d; } 

 $ man pcrepattern $ man pcresyntax 

由于您在静态文件的位置使用正则expression式,因此只需将!pptx?\.swf条件添加到它并排除条件swf

您的位置将如下所示:

 位置〜*。(avi | bin | bmp | ... |!pptx?\。swf)$ {
         root / var / www / html1;
         access_logclosures;
        到期1d;
 } 

不要忘记为*.swf文件添加单独的位置:

位置〜* [0-9a-z] * \。swf $
         root / var / www / html1;
         access_logclosures;
        到期1d;
 }