# Block certain extensions preferably across virtual hosts

**URL:** <https://www.ruby-forum.com/t/block-certain-extensions-preferably-across-virtual-hosts/198801>\
**Category:** NGINX\
**Created:** [November 8, 2010, 9:37am UTC](https://www.ruby-forum.com/t/block-certain-extensions-preferably-across-virtual-hosts/198801 "2010-11-08T09:37:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [November 8, 2010, 9:37am UTC](https://www.ruby-forum.com/t/block-certain-extensions-preferably-across-virtual-hosts/198801/1 "2010-11-08T09:37:17Z")

</div>

I have been working on converting from apache to nginx and I have a  
rule

RewriteRule .(asp|aspx|php|jsp)$ - [F,L]

to block all of those. What would be the best way to convert that to  
nginx and is there a way to do it in one place so that all  
virtualhosts share it?

If I could put that in one place so it applies to everything I serve  
with nginx it would be much easier to add other things to it over time.  
Mostly I want to completely block many extensions since it makes  
analyzing errors much simpler.

Thanks

Posted at Nginx Forum:

> **[Block certain extensions preferably across virtual hosts](https://forum.nginx.org/read.php?2,148723,148723#msg-148723)**
>
> I have been working on converting from apache to nginx and I have a rule RewriteRule \\.(asp|aspx|php|jsp)$ - \[F,L\] to block all of those. What would be the best way to convert that to nginx and is there a way to do it in one place so that all...

---

<div class="post-metadata">

**Author:** ![kosh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/77aa72/32.png) [@kosh](https://www.ruby-forum.com/u/kosh)\
**Post date:** [November 8, 2010, 12:20pm UTC](https://www.ruby-forum.com/t/block-certain-extensions-preferably-across-virtual-hosts/198801/2 "2010-11-08T12:20:39Z")

</div>

On Mon, Nov 08, 2010 at 03:36:04AM -0500, kosh wrote:

> I have been working on converting from apache to nginx and I have a  
> rule
> 
> RewriteRule .(asp|aspx|php|jsp)$ - [F,L]
> 
> to block all of those. What would be the best way to convert that to  
> nginx and is there a way to do it in one place so that all  
> virtualhosts share it?

Place this as the first location of virtual host:

location ~ .(asp|aspx|php|jsp)$ {  
return 403;  
}

You may also include it as a file.

> If I could put that in one place so it applies to everything I serve  
> with nginx it would be much easier to add other things to it over time.  
> Mostly I want to completely block many extensions since it makes  
> analyzing errors much simpler.

This is common mistake that such single place makes administration  
easier.  
Suppose, eventually you do not need to block .php in some new site.  
What will you do ?

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**
