Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

tomcat响应文件的mime type的问题

现在有几个自定义类型的文件:
A.data.gz
A.framework.js.gz
A.wasm.gz
我在web.xml里配置了

<mime-mapping>
    <extension>data.gz</extension>
    <mime-type>application/octet-stream</mime-type>
</mime-mapping>
<mime-mapping>
    <extension>wasm.gz</extension>
    <mime-type>application/wasm</mime-type>
</mime-mapping>
<mime-mapping>
    <extension>js.gz</extension>
    <mime-type>application/javascript</mime-type>
</mime-mapping>

但是tomcat似乎并不能正确区分这几种文件类型的后缀名,请问应该怎么配置才能让tomcat返回正确的文件呢


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

gzip压缩应该是http协议层自动完成的。这里不应该加.gz

tomcat 不具备服务事先压缩的文件,你如果一定要用 tomcat 实现,可以写一个 filter, 当用户请求对应的静态资源时,读取相应的.gz文件并返回。

但更好的方案是在 tomcat 前套一个 nginx 来完成相应的功能。性能要比 tomcat 好很多。

nginx 相应的配置很简单,仅需要

gzip_static on;

参见:http://nginx.org/en/docs/http...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...