


Linux Notes (68) - nginx cache configuration and other configurations
Configure cache
In the nginx configuration file, there is a location node under the server node to configure the cache time
For example:
<code>server{ <span>#其他配置</span><span>#以.png .jpg结尾的都缓存30天</span> location ~.*\.(jpg|png)<span>${</span> expires <span>30</span>d; } <span>#以.css .js结尾的都缓存1个小时</span> location ~.*\.(css|js)<span>${</span> expires <span>1</span>d; } }</code>
Compression function configuration
gzip compression technology: Through gzip, the content size of the original web page can be compressed to 30% of the original, this can improve access speed
In the configuration file, you can find gzip
Remove the comment to turn on the gzip function
But for some very small files, the cost of compressing them will be higher High, so we need to configure files smaller than the size to be compressed. Officials say that files smaller than 1k will be larger than 1k after compression
At the same time, the compressed files are stored in memory, so we also need to configure the size of the memory space applied for
The configuration is as follows:
<code><span>#开启gzip功能</span> gzip on; <span>#小于1k的文件不压缩</span> gzip_min_length <span>1</span>k; <span>#申请内存空间大小为4个16k的流</span> gzip_buffers <span>4</span><span>16</span>k; <span>#http版本,如果不是这个版本,就不压缩</span> gzip_http_version <span>1.1</span>; <span>#需要客户端浏览器也支持gzip才行,这句表示开启验证浏览器是否支持,支持的话才进行压缩</span> gzip_vary on;</code>
Automatic listing of directories
Enable After the automatic directory listing function: If you visit a server, the default page is index.html, but there is no index.html file under the server, then the directories under the server will be automatically listed
The effect is just like our common The same as the mirror site:
Configuration method: add autoindex on; under location
<code>location / { <span>#其他配置...</span> autoindex <span><span>on</span>;</span> }</code>
The above introduces Linux Notes (68) - nginx cache configuration and other configurations, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



Nginx turns on the Gzip compression function, which can compress the css, js, xml, and html files of the website during transmission, improve the access speed, and then optimize the performance of Nginx! Images, videos and other multimedia files and large files on the Web website are compressed due to compression The effect is not good, so there is no need to support compression for images. If you want to optimize, you can set the life cycle of the image to be longer and let the client cache it. After turning on the Gzip function, the Nginx server will compress the sent content, such as css, js, xml, html and other static resources according to the configured policy, so that the size of the content is reduced, and the user will process it before receiving the returned content. The compressed data is displayed to the customer. so

Dynamic compression Dynamic compression actually means that the nginx server compresses the compiled creation. You need to enable the following configuration in the http and https modules of nginx.conf: gzipon; #Enable gizo compression gzip_min_length1k; #gizp compression starting point, only if the file is larger than 1k Compression gzip_comp_level6;#The larger the compression level number, the smaller the compression, but the more performance consumption depends on the actual situation gzip_proxiedany;#Enabled when nginx is used as a reverse proxy. For details, see the official documentation: http://nginx.org/en/docs /http/ngx_http_gzip

First, let me briefly introduce the types of location and matching rules, using the example of nginxwiki as an example: location=/{#matchesthequery/only.[configurationa]}location/{#matchesanyquery,sinceallqueriesbeginwith/,butregular#expressionsandanylongerconventionalblockswillbe#matchedfirst.[ configurationb]}location^~/im

Note: The root and aliasroot instructions in location only set the search root to the directory set by root, that is, the uri will not be truncated. Instead, the original uri will be used to jump to the directory to find the file. The aias instruction will truncate the matching uri, and then Use the path set by alias plus the remaining uri as a sub-path to find the uri of proxy_pass in location. If the url of proxy_pass does not have uri, if the tail is "/", the matching uri will be truncated. If the tail is not "/", then Will not truncate the matching uri if the proxy_pass url contains uri

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 front-end or 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. Generally used on the server side is u

目录1:basename()2:copy()3:dirname()4:disk_free_space()5:disk_total_space()6:file_exists()7:file_get_contents()8:file_put_contents()9:filesize()10:filetype()11:glob()12:is_dir()13:is_writable()14:mkdir()15:move_uploaded_file()16:parse_ini_file()17:

In Linux, the gzip command is used to compress and decompress files. The extension of the new file compressed by this command is usually marked as ".gz", and the syntax is "gzip [option] source file". The source file in the syntax refers to an ordinary file when performing a compression operation; when performing a decompression operation, it refers to a compressed file. The gzip command can only be used to compress files, not directories. Even if a directory is specified, it can only compress all files in the directory. gzip is a command often used to compress and decompress files in Linux systems. The extension of a new file compressed by this command is usually marked as ".gz". Let me emphasize again that the gzip command can only be used to compress files, not objects.

Location tutorial example: location=/{#Exact match/, the host name cannot be followed by any string [configurationA]}location/{#Because all addresses begin with /, this rule will match all requests#But regular and the longest string will be matched first [configurationB]}location/documents/{#Match any address starting with /documents/. After matching, continue to search downwards#Only when the subsequent regular expression is not matched, This article will use [configurationC]}location~/document
