有条件地改变nginx中的MIMEtypes

我使用nginx作为Rails的前端。 所有页面都caching为磁盘上的.html文件,如果存在,nginx将提供这些文件。 我想发送正确的MIMEtypes的饲料( application/rss+xml ),但我迄今的方式是相当丑陋的,我想知道是否有一个更干净的方式。

这是我的configuration:

 location ~ /feed/$ { types {} default_type application/rss+xml; root /var/www/cache/; if (-f request_filename/index.html) { rewrite (.*) $1/index.html break; } if (-f request_filename.html) { rewrite (.*) $1.html break; } if (-f request_filename) { break; } if (!-f request_filename) { proxy_pass http://mongrel; break; } } location / { root /var/www/cache/; if (-f request_filename/index.html) { rewrite (.*) $1/index.html break; } if (-f request_filename.html) { rewrite (.*) $1.html break; } if (-f request_filename) { break; } if (!-f request_filename) { proxy_pass http://mongrel; break; } } 

我的问题:

  1. 有没有更好的方法来改变MIMEtypes? 所有caching的文件都有.html扩展名,我无法更改。
  2. 有没有一种方法来分解/feed/$/if条件? 我明白,我可以使用include ,但我希望有一个更好的方法。 把configuration的一部分放在不同的文件中是不可读的。
  3. 你可以发现任何错误的条件?

我正在使用nginx 0.6.32(Debian Lenny)。 我更喜欢在APT中使用该版本。

谢谢。

我的build议是:转到Nginx 0.7.x并使用try_filesproxy_cache ,它将简化您的设置。 try_files被devise用来try_files重复的if (-f语句:

 location / { try_files $uri/index.html $uri.html $uri @mongrel } location @mongrel { proxy_pass http://mongrel; } 

至于MIMEtypes,如果使用proxy_cache ,则可以从应用程序返回MIMEtypes,Nginx会caching它。