在Nginx中为CSV文件复制Content-Type标头

时间:2011-03-22 17:35:40

标签: nginx

我有一些.csv个文件,我直接从文件系统通过Nginx提供服务。 它目前看起来像这样::

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

出于某种原因,我必须这样做,因为否则它将被视为text/plain。这是我卷曲时得到的结果:

$ 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,它工作正常,但我怀疑我做得不对。

1 个答案:

答案 0 :(得分:4)

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