Home > Backend Development > PHP Tutorial > Linux Notes (68) - nginx cache configuration and other configurations

Linux Notes (68) - nginx cache configuration and other configurations

WBOY
Release: 2016-07-29 08:57:20
Original
892 people have browsed it

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>
Copy after login

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

Linux Notes (68) - nginx cache configuration and other configurations

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>
Copy after login

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:

Linux Notes (68) - nginx cache configuration and other configurations

Configuration method: add autoindex on; under location

<code>location / {
<span>#其他配置...</span>    autoindex <span><span>on</span>;</span>
}</code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template