try_files and content type

Xavier Grangier grangier at gmail.com
Sat Feb 14 12:50:28 MSK 2009


Hello,

I have an issue with try_files and content-type ( nginx 0.7.34 ), it  
doesn't use the cache file extention to discover the mime.type
so if we call a direct file host/sitemap.xml content type is ok, but  
if I call a directory host/faq/ the returned content-type is the  
default.

My default_type is set to application/octet-stream, my application
is directory base ( host/faq/, host/register/ ), I only have a few  
call to files ( host/robots.txt host/sitemap.xml )

Most of the content is text/html but I can be sometimes for exemple  
text/xml or application/pdf.

For instance /cachedir/faq/host.index.html is the cache file for http://host/faq 
  ( I use host in the cache file name to handle languages )
I could have a pdf version of the faq at the following url http://host/faq/pdf/ 
  then the cache file would be /cachedir/faq/pdf/host.index.pdf

the problem is that once cached try_file would return the default_type  
for all those urls.

I don't know if this is the expected beavhiour, I expected try_files  
to return the type according to the cache file extension. Of course I  
can
use text/html as default type but in this case I cannot handle  
multiple types fils within the same location.

with the old fashion way:

if (-f $request_filename/$host.index.html) { rewrite (.*) $uri/ 
$host.index.html break; }
if (-f $request_filename/$host.index.pdf) { rewrite (.*) $uri/ 
$host.index.pdf break; }

types where correct.

Below three tests, first one a direct call returning content type is  
the one expected.
Then my expected result would have been text/html instead of  
application/octet-stream

xav - is sorry for poor english xD


------------------------------------------------------------------------------------------

http {
     include /etc/nginx/mime.types;
     include /etc/nginx/fastcgi_params;
     index index.html;
     default_type application/octet-stream;

     server {
         listen 10.0.0.181;
         server_name devel.1cafe.fr;
         root /home/cache/hard;
         error_page 599 = @django;

         location @django {
             fastcgi_pass localhost:3000;
         }

         location / {
             # default_type text/html;
             # try_files $uri$host.index.html $uri$host.index.pdf  
@django;
             # test purpose
             try_files $uri $uri/index.html $uri$host.index.html $uri 
$host.index.pdf @django;
         }
     }
}

GET devel.1cafe.fr/sitemap.xml

2009/02/14 10:09:40 [debug] 22727#0: *1 http script var: "/sitemap.xml"
2009/02/14 10:09:40 [debug] 22727#0: *1 try to use file: "/sitemap.xml"
2009/02/14 10:09:40 [debug] 22727#0: *1 try file uri: "/sitemap.xml"
2009/02/14 10:09:40 [debug] 22727#0: *1 http filename: "/home/cache/ 
hard/sitemap.xml"
2009/02/14 10:09:40 [debug] 22727#0: *1 http set discard body
2009/02/14 10:09:40 [debug] 22727#0: *1 HTTP/1.1 200 OK
Server: nginx
Date: Sat, 14 Feb 2009 09:09:40 GMT
Content-Type: text/xml
Content-Length: 870
Last-Modified: Sat, 14 Feb 2009 08:51:51 GMT
Connection: close
Served-By: intra2
Accept-Ranges: bytes


GET devel.1cafe.fr/

2009/02/14 10:11:01 [debug] 22727#0: *2 http script copy: "/index.html"
2009/02/14 10:11:01 [debug] 22727#0: *2 try to use file: "//index.html"
2009/02/14 10:11:01 [debug] 22727#0: *2 try file uri: "//index.html"
2009/02/14 10:11:01 [debug] 22727#0: *2 http filename: "/home/cache/ 
hard//index.html"
2009/02/14 10:11:01 [debug] 22727#0: *2 http set discard body
2009/02/14 10:11:01 [debug] 22727#0: *2 HTTP/1.1 200 OK
Server: nginx
Date: Sat, 14 Feb 2009 09:11:01 GMT
Content-Type: application/octet-stream
Content-Length: 57050
Last-Modified: Sat, 14 Feb 2009 08:37:55 GMT
Connection: close
Served-By: intra2
Accept-Ranges: bytes

GET http://devel.1cafe.fr/faq/

2009/02/14 10:12:46 [debug] 22727#0: *25 http script copy: ".index.html"
2009/02/14 10:12:46 [debug] 22727#0: *25 try to use file: "/faq/devel. 
1cafe.fr.index.html"
2009/02/14 10:12:46 [debug] 22727#0: *25 try file uri: "/faq/devel. 
1cafe.fr.index.html"
2009/02/14 10:12:46 [debug] 22727#0: *25 http filename: "/home/cache/ 
hard/faq/devel.1cafe.fr.index.html"
2009/02/14 10:12:46 [debug] 22727#0: *25 http set discard body
2009/02/14 10:12:46 [debug] 22727#0: *25 HTTP/1.1 200 OK
Server: nginx
Date: Sat, 14 Feb 2009 09:12:46 GMT
Content-Type: application/octet-stream
Content-Length: 44232
Last-Modified: Sat, 14 Feb 2009 09:12:40 GMT
Connection: close
Served-By: intra2
Accept-Ranges: bytes







More information about the nginx mailing list