# Applying NGINX location based on unlisted extension of default file?

**URL:** <https://www.ruby-forum.com/t/applying-nginx-location-based-on-unlisted-extension-of-default-file/238755>\
**Category:** NGINX\
**Created:** [January 27, 2014, 6:51pm UTC](https://www.ruby-forum.com/t/applying-nginx-location-based-on-unlisted-extension-of-default-file/238755 "2014-01-27T18:51:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [January 27, 2014, 6:51pm UTC](https://www.ruby-forum.com/t/applying-nginx-location-based-on-unlisted-extension-of-default-file/238755/1 "2014-01-27T18:51:43Z")

</div>

I’m trying to create a second location in NGINX that will only fire for  
a  
specific file type. Specifically, I have NGINX acting as a proxy for a  
server that primarily serves PHP files. There are, however, a bunch of  
folders that also have ASPX files (more than 120), and I need to use a  
different configuration when serving them (different caching rules,  
different Modsecurity/NAXSI rules, etc).

NGINX is successfully detecting the file type and applying the alternate  
location when the file name is specifically listed, but it’s breaking  
when  
the ASPX file is the default file in the folder and the URL simply ends  
in a  
slash. When that happens, it’s just applying the root location  
configuration. Is there a way to detect the extension of an index file  
and  
apply an alternate location, even when the name of the index file isn’t  
specifically entered?

server {  
listen 80;  
server\_name [mysite.com](http://mysite.com);

```
 location / {
        #general settings applicable to most files go here
        proxy_pass http://@backend;
 }

  location ~* \.(aspx|asmx) {
        #slightly different settings applicable to .Net files go 

```

here  
proxy\_pass http://@backend;  
}  
}

If a folder has an index file called “default.aspx”, the above  
configuration  
works perfectly if I enter the url as [mysite.com/folder/default.aspx](http://mysite.com/folder/default.aspx),  
but it  
fails to apply the second location and applies the base location if I  
enter  
it as [mysite.com/folder](http://mysite.com/folder), even though it is serving the exact same  
default.aspx file.

The only solution I’ve found is to alter the location directive to  
identify  
by the folder name instead of the file extension, but this doesn’t scale  
well as there are more than 120 affected folders on the server and I’d  
end  
up with a huge conf file.

Is there any way to specify a location by file extension, when the file  
isn’t specifically named in the URL? Can I test a folders index file to  
determine its extension before a location is applied?

Posted at Nginx Forum:

> **[Applying NGINX location based on unlisted extension of default file?](https://forum.nginx.org/read.php?2,246883,246883#msg-246883)**
>
> I'm trying to create a second location in NGINX that will only fire for a specific file type. Specifically, I have NGINX acting as a proxy for a server that primarily serves PHP files. There are, however, a bunch of folders that also have ASPX files...
