gzip on; #开启Gzipgzip_static on; #是否开启gzip静态资源 #nginx对于静态文件的处理模块, the module can read the pre-compressed GZ files, which reduces the CPU resource consumption per request for gzip compression. When the module is enabled, Nginx first checks if there is a file at the end of GZ that requests a static file, and if so, returns the contents of the GZ file directly. In order to be compatible with browsers that do not support gzip, enabling the Gzip_static module must preserve both the original static file and the Gz file. In this case, the disk space will be greatly increased with a large number of static files. We can make use of Nginx's reverse proxy function to keep GZ files only. Gzip_min_length 1k; #不压缩临界值, more than 1K compression, generally do not change gzip_buffers416k; #buffer, yes, well, don't explain, don't change #gzip_http_version.1.0;//with the reverse proxy, the end of the communication is http/1.0, there should be no need to see me this popular science, I have this sentence to comment on the line, the default is http/1.1Gzip_comp_level2; # compression level,1-Ten, the greater the number of compression, the better, the longer the time! Gzip_types text/plain application/x-javascript application/javascript text/javascript text/css application/xml application/ x-httpd-php image/jpeg image/gif image/PNG; # to compress the file type, what is missing what to do, JavaScript has two kinds of writing, it is best to write it, there are people complaining that JS files are not compressed, in fact, write a format on the line gzip_vary off; #跟Squid等缓存服务有关, On the words will be added in the header"vary:accept-encoding"I don't need this stuff, I'm going to look at it in my own case. Gzip_disable"MSIE [1-6]\."; #IE6对Gzip不怎么友好, don't give it gzip.
Verify:
After you enable compression, you can use the browser F12 development mode for verification, or login to the following address:
http://pagespeed.webkaka.com/
Front Page loading speed optimization---ngnix gzip compression