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.