天天看點

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  p_w_picpath/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

繼續閱讀