I’m using Rails 3.1 and NGINX.
What I do with my websites is I use a URL hashbang + popstate trick to reload the URL while then using AJAX to download the next page. Rails then recognizes that this is a AJAX request and then delivers the view without the layout (or a stripped down version). This works, but when I try to cache the output into my own extension (called plain_html) then NGINX doesn’t allow the URL rewriting to work.
I’m caching my Rails page cached files into a cache directory located on the public folder. These are my URL rewrites for my HTML files.
if (-f $document_root/cache/$uri/index.html) {
rewrite (.*) /cache/$1/index.html break;
}
if (-f $document_root/cache/$uri.html) {
rewrite (.*) /cache/$1.html break;
}
if (-f $document_root/cache/$uri) {
rewrite (.*) /cache/$1 break;
}
The first two are for anything that is without a HTML extension and the final one is a catch all for anything in the cache folder. The last one should basically work for anything that has a different extension and that is found within the cache folder like:
GET /articles # -> /cache/articles.html
GET /articles.html # -> /cache/articles.html
GET /articles.plain_html # -> /cache/articles.plain_html
This does not seem to work for the final option. It forces the browser to download it (if I access it in the address bar) and the contents of the downloaded file are not the cached contents (I tried adding words directly into the cache file).
I’ve configured NGINX to add this as a mime_type and I’m sure that the mime type does work because when I do:
GET /cache/articles.plain_html # -> this works fine
It works directly. So something is going on with the rewriting. Any ideas as to what I should do?
BTW this plain_html rewriting technique works fine using Apache.
The solution is to register a mime-type within NGINX for the
plain_htmlfile or set the default_type to content/html.