Preface
gzip (gnu-zip) is a compression technology. After gzip compression, the page size can be reduced to 30% or even smaller than the original size. In this way, users will browse the page much faster. The gzip compressed page needs to be supported by both the browser and the server. It is actually server-side compression. After being transmitted to the browser, the browser decompresses and parses it. We don’t need to worry about the browser, because most current browsers support parsing gzip pages.
Whether it is the front-end or the back-end, nginx is often used when deploying projects, and small projects often use a reverse proxy or something. Today I will be simple and direct and talk about one of the points - gzip. If there are any errors, please correct me.
Ubuntu, centos, linux, etc. are commonly used on the server side. If you don’t have a server, you can play it locally.
mac installation
You can install it directly with brew under mac. If brew is not installed, you can install it first
/usr/bin/ruby -e "$(curl -fssl https://raw.githubusercontent.com/homebrew/install/master/install)" brew install nginx
Default configuration
After the installation is completed, you will see that the command line contains the following information. You can see the path where nginx.conf is located. This is the configuration file we are looking for. It also contains port information. When starting nginx, you can directly access http://localhost:8080. When you see the page shown in the figure below, the installation is started successfully.
docroot: /usr/local/var/www default config: /usr/local/etc/nginx/nginx.conf port:8080
Several common commands
Start: nginx
Restart warmly: nginx -s reload
Shut down: nginx -s stop
Test syntax: nginx -t
##gizp configuration:
http{} or
server{} or
location{} level, if there are duplicate settings at different levels The priority is
location{} > server{} > http{}
gzip on;
gzip_http_version 1.0;
gzip_disable "msie [1-6]";
gzip_comp_level 5;
gzip_min_length 20;
gzip_proxied any;
gzip_http_version 1.0;
gzip_vary on;
gzip_types application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/javascript text/x-component;
location{} or
server{} level.
gzip_static on;
gzip_buffers 16 8k;
The above is the detailed content of Nginx basic introduction to gzip configuration method. For more information, please follow other related articles on the PHP Chinese website!