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;2, gzip http version
gzip_http_version 1.0;3. Prohibit ie6 from gzip compression (of course, almost no one uses ie6 now)
gzip_disable "msie [1-6]";4. Compression level (1~9, generally balanced file size When used with CPU, 5 is a commonly used value, which of course depends on the actual machine)
gzip_comp_level 5;5. Minimum compression threshold (the default is 20 bytes)
gzip_min_length 20;6. Compress client data linked through the proxy
gzip_proxied any;7. The default http protocol version is 1.1, and requests for 1.0 will not be compressed. If set to 1.0, it means http1.0 or above The versions will be compressed. (If proxy_pass is used for reverse proxy, the communication between nginx and the back-end upstream server uses the http/1.0 protocol by default.)
gzip_http_version 1.0;8. Proxy cache compression and original version resources, Avoid client errors due to accept-encoding not supporting gzip (gzip is generally used now)
gzip_vary on;9. Compressed file type (the default is always to compress text/html type, which is specially stated It is best to add both application/javascript and text/javascript. If the types of script tags on the page are different, some js files may not be compressed. The default type is application/javascript)
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;10. If there are compressed (.gz) or static file services, you can set it to on. If this is not the case, it is best to set it to off as this will cause additional I/O overhead. A better way to handle it is to handle it separately at the
location{} or
server{} level.
gzip_static on;11. The space used to store the compression result data stream is expressed as 8k as the unit. Apply for memory in 16 times the original data size in 8k units. The default value is to apply for the same size memory space as the original data to store the gzip compression result.
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!

The reason why NGINX is popular is its advantages in speed, efficiency and control. 1) Speed: Adopt asynchronous and non-blocking processing, supports high concurrent connections, and has strong static file service capabilities. 2) Efficiency: Low memory usage and powerful load balancing function. 3) Control: Through flexible configuration file management behavior, modular design facilitates expansion.

The differences between NGINX and Apache in terms of community, support and resources are as follows: 1. Although the NGINX community is small, it is active and professional, and official support provides advanced features and professional services through NGINXPlus. 2.Apache has a huge and active community, and official support is mainly provided through rich documentation and community resources.

NGINXUnit is an open source application server that supports a variety of programming languages and frameworks, such as Python, PHP, Java, Go, etc. 1. It supports dynamic configuration and can adjust application configuration without restarting the server. 2.NGINXUnit supports multi-language applications, simplifying the management of multi-language environments. 3. With configuration files, you can easily deploy and manage applications, such as running Python and PHP applications. 4. It also supports advanced configurations such as routing and load balancing to help manage and scale applications.

NGINX can improve website performance and reliability by: 1. Process static content as a web server; 2. forward requests as a reverse proxy server; 3. allocate requests as a load balancer; 4. Reduce backend pressure as a cache server. NGINX can significantly improve website performance through configuration optimizations such as enabling Gzip compression and adjusting connection pooling.

NGINXserveswebcontentandactsasareverseproxy,loadbalancer,andmore.1)ItefficientlyservesstaticcontentlikeHTMLandimages.2)Itfunctionsasareverseproxyandloadbalancer,distributingtrafficacrossservers.3)NGINXenhancesperformancethroughcaching.4)Itofferssecur

NGINXUnit simplifies application deployment with dynamic configuration and multilingual support. 1) Dynamic configuration can be modified without restarting the server. 2) Supports multiple programming languages, such as Python, PHP, and Java. 3) Adopt asynchronous non-blocking I/O model to improve high concurrency processing performance.

NGINX initially solved the C10K problem and has now developed into an all-rounder who handles load balancing, reverse proxying and API gateways. 1) It is well-known for event-driven and non-blocking architectures and is suitable for high concurrency. 2) NGINX can be used as an HTTP and reverse proxy server, supporting IMAP/POP3. 3) Its working principle is based on event-driven and asynchronous I/O models, improving performance. 4) Basic usage includes configuring virtual hosts and load balancing, and advanced usage involves complex load balancing and caching strategies. 5) Common errors include configuration syntax errors and permission issues, and debugging skills include using nginx-t command and stub_status module. 6) Performance optimization suggestions include adjusting worker parameters, using gzip compression and

Diagnosis and solutions for common errors of Nginx include: 1. View log files, 2. Adjust configuration files, 3. Optimize performance. By analyzing logs, adjusting timeout settings and optimizing cache and load balancing, errors such as 404, 502, 504 can be effectively resolved to improve website stability and performance.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Notepad++7.3.1
Easy-to-use and free code editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
