nginx tomcat 開啓gzip

從新編譯nginx 

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --without-http-cache --with-http_ssl_module --with-http_realip_module --with-ipv6 --with-http_gzip_static_module --with-http_gunzip_module


注 --with-http_gzip_static_module --with-http_gunzip_module 都需要遍以上否則二級目錄會不生效


nginx配置文件開啓gzip


gzip on;

    gzip_vary on;

    gzip_proxied any;

    gzip_min_length 1000;

    gzip_buffers 4 16k;

    gzip_types  image/png text/plain application/x-javascript  text/css application/xml text/javascript text/xml application/xml+rss application/json;


測試網站    

 http://pagespeed.webkaka.com/youhua/gzip/

 將輸出結果的Content-Type 加入 nginx配置文件gzip_types 後面重啓

 

服務器如果用的阿里雲並且使用了負載均衡,將監聽協議改成四層監聽(tcp)如果是http的話gzip是不生效的

或者開啓tomcat的gzip功能關閉阿里雲和nginx的gzip功能


tomcat開啓gzip 

編輯server.xml

在監聽端口的下面添加

compression="on"

compressionMinSize="50" noCompressionUserAgents="gozilla, traviata"

compressableMimeType=" application/json,text/html,text/xml,text/javascript,text/css,text/plain"


重啓tomcat


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章