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!

NGINXUnit is an open source application server that supports multiple programming languages and provides functions such as dynamic configuration, zero downtime updates and built-in load balancing. 1. Dynamic configuration: You can modify the configuration without restarting. 2. Multilingual support: compatible with Python, Go, Java, PHP, etc. 3. Zero downtime update: Supports application updates that do not interrupt services. 4. Built-in load balancing: Requests can be distributed to multiple application instances.

NGINXUnit is better than ApacheTomcat, Gunicorn and Node.js built-in HTTP servers, suitable for multilingual projects and dynamic configuration requirements. 1) Supports multiple programming languages, 2) Provides dynamic configuration reloading, 3) Built-in load balancing function, suitable for projects that require high scalability and reliability.

NGINXUnit improves application performance and manageability with its modular architecture and dynamic reconfiguration capabilities. 1) Modular design includes master processes, routers and application processes, supporting efficient management and expansion. 2) Dynamic reconfiguration allows seamless update of configuration at runtime, suitable for CI/CD environments. 3) Multilingual support is implemented through dynamic loading of language runtime, improving development flexibility. 4) High performance is achieved through event-driven models and asynchronous I/O, and remains efficient even under high concurrency. 5) Security is improved by isolating application processes and reducing the mutual influence between applications.

NGINXUnit can be used to deploy and manage applications in multiple languages. 1) Install NGINXUnit. 2) Configure it to run different types of applications such as Python and PHP. 3) Use its dynamic configuration function for application management. Through these steps, you can efficiently deploy and manage applications and improve project efficiency.

NGINX is more suitable for handling high concurrent connections, while Apache is more suitable for scenarios where complex configurations and module extensions are required. 1.NGINX is known for its high performance and low resource consumption, and is suitable for high concurrency. 2.Apache is known for its stability and rich module extensions, which are suitable for complex configuration needs.

NGINXUnit improves application flexibility and performance with its dynamic configuration and high-performance architecture. 1. Dynamic configuration allows the application configuration to be adjusted without restarting the server. 2. High performance is reflected in event-driven and non-blocking architectures and multi-process models, and can efficiently handle concurrent connections and utilize multi-core CPUs.

NGINX and Apache are both powerful web servers, each with unique advantages and disadvantages in terms of performance, scalability and efficiency. 1) NGINX performs well when handling static content and reverse proxying, suitable for high concurrency scenarios. 2) Apache performs better when processing dynamic content and is suitable for projects that require rich module support. The selection of a server should be decided based on project requirements and scenarios.

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.


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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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.

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Atom editor mac version download
The most popular open source editor
