Why use gzip compression?By turning on gzip compression in nginx, the size of static resources such as js and css in the web page will be greatly reduced, thus saving a lot of bandwidth, improving transmission efficiency, and giving users a fast experience. nginx implements gzip The principle of resource compression in nginx is to intercept requests through the default integrated Request header and response header after gzip takes effect Request Headers: Accept-Encoding:gzip,deflate,sdch Response Headers: Content-Encoding:gzip Cache-Control:max-age240 gzip processing From the perspective of the HTTP protocol, the request header declares acceopt-encoding:gzip deflate sdch (refers to the compression algorithm, where sdch is a compression method promoted by Google itself) Common configuration parameters of gzip
nginx configuration gzipStatic page index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Demonstrating nginx gzip compression</title> <script src="./jquery.js" ></script> </head> <body> <img src="./nginx_img.jpeg" style="width: 100px;height: 100px;" /> <h1>nginx implements gzip compression to reduce bandwidth usage and improve website speed</h1> <h1>nginx implements gzip compression to reduce bandwidth usage and improve website speed</h1> <h1>nginx implements gzip compression to reduce bandwidth usage and improve website speed</h1> <h1>nginx implements gzip compression to reduce bandwidth usage and improve website speed</h1> <h1>nginx implements gzip compression to reduce bandwidth usage and improve website speed</h1> <h1>nginx implements gzip compression to reduce bandwidth usage and improve website speed</h1> </body> </html> nginx configuration server{ listen 80; server_name localhost 192.168.0.96; gzip on; gzip_buffers 32 4k; gzip_comp_level 6; gzip_min_length 200; gzip_types application/javascript application/x-javascript text/javascript text/xml text/css; gzip_vary off; root /Users/lidong/Desktop/wwwroot/test; index index.php index.html index.htm; access_log /Users/lidong/wwwlogs/access.log; error_log /Users/lidong/wwwlogs/error.log; location ~ [^/]\.php(/|$) { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } To use the page request before gzip: Requests with gzip enabled: Notice
Summarize The above is the implementation method of gzip compression in nginx to improve website speed introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time! You may also be interested in:
|
<<: Detailed installation steps for MySQL 8.0.11
>>: MySQL 8.0.12 installation and configuration method graphic tutorial (windows10)
I have installed various images under virtual mac...
01 The concept of parallel replication In the mas...
First look at the effect: When the mouse moves ov...
There is a medicine for regret in the world, as l...
Method 1: Command line modification We only need ...
When using <a href="" onclick="&...
In actual use, it is often necessary to share the...
I recently started learning the NestJs framework....
Table of contents 1. Parameters that determine ca...
Provide login and obtain user information data in...
Table of contents Ideas Host Configuration Modify...
Table of contents Constructing payment methods us...
Preface: In interviews for various technical posi...
1. Install JDK Check the computer's operating...
Preface The most common task after we install a L...