Nginx中的CSV文件有重复的Content-Type标头 [英] Duplicate Content-Type headers in Nginx for CSV files

查看:449
本文介绍了Nginx中的CSV文件有重复的Content-Type标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从文件系统直接通过Nginx提供了一些.csv文件. 当前看起来像这样:

I have some .csv files that I'm serving via Nginx straight from the filesystem. It currently looks like this::

location ~ /static/csv_exports/ {
        add_header Content-Type text/csv;
}

由于某种原因,我必须这样做,因为否则它将用作text/plain.这是我卷曲时得到的:

For some reason I had to do that because otherwise it would be served as text/plain. Here's what I get when I do a curl on it:

$ curl -v http://localhost/static/csv_exports/20110322_172651.csv >> /dev/null
...
 < HTTP/1.1 200 OK
 < Server: nginx/0.7.67
 < Date: Tue, 22 Mar 2011 17:32:07 GMT
 < Content-Type: text/plain
 < Content-Length: 356623
 < Last-Modified: Tue, 22 Mar 2011 17:26:52 GMT
 < Connection: keep-alive
 < Cache-Control: public
 < Content-Type: text/csv
 < Accept-Ranges: bytes

瞧!它有两个"Content-Type"标头.在浏览器中打开它会自动打开Open Office,效果很好,但是我怀疑我做得不好.

See! It's got two "Content-Type" headers. Opening it in the browser automatically opens Open Office and it works just fine but I suspect I haven't done it right.

推荐答案

location ~ /static/csv_exports/ {
-    add_header Content-Type text/csv;
+    types {text/csv csv;}
}

这篇关于Nginx中的CSV文件有重复的Content-Type标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆