Applying NGINX location based on unlisted extension of default file?

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;

 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,
but it
fails to apply the second location and applies the base location if I
enter
it as 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:
http://forum.nginx.org/read.php?2,246883,246883#msg-246883

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs