7.nginx服务之缓存服务配置

1.配置语法
Syntax:	proxy_cache_path path [levels=levels] [use_temp_path=on|off] keys_zone=name:size [inactive=time] [max_size=size] [manager_files=number] [manager_sleep=time] [manager_threshold=time] [loader_files=number] [loader_sleep=time] [loader_threshold=time] [purger=on|off] [purger_files=number] [purger_sleep=time] [purger_threshold=time];
Default:	—
Context:	http
2.proxy_cache配置语法
Syntax:	proxy_cache zone | off;
Default:	proxy_cache off;
Context:	http, server, location
3.配置语法- 缓存过期周期
Syntax:	proxy_cache_valid [code ...] time;
Default:	—
Context:	http, server, location
4.配置语法-缓存的维度
Syntax:	proxy_cache_key string;
Default:	proxy_cache_key $scheme$proxy_host$request_uri;
Context:	http, server, location
​```nginx
upstream imooc {
    server 116.62.103.228:8001;
    server 116.62.103.228:8002;
    server 116.62.103.228:8003;
}

proxy_cache_path /opt/app/cache levels=1:2 keys_zone=imooc_cache:10m max_size=10g inactive=60m use_temp_path=off;

server {
listen 80;
server_name localhost;

location / {
    proxy_cache off;
    proxy_pass http://imooc;
    proxy_cache_valid 200 304 12h;
    proxy_cache_valid any 10m;
    proxy_cache_key $host$uri$is_args$args;
    add_header  Nginx-Cache "$upstream_cache_status";  
    
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
    include proxy_params;
}

}
```

5.部分页面不缓存
Syntax:	proxy_no_cache string ...;
Default:—
Context:http, server, location
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    access_log  /var/log/nginx/test_proxy.access.log  main;
	
    if ($request_uri ~ ^/(url3|login/register|password\/reset)){
        set $cookie_nochache 1;
    }
    
    location / {
        proxy_cache off;
        proxy_pass http://imooc;
        proxy_cache_valid 200 304 12h;
        proxy_cache_valid any 10m;
        proxy_cache_key $host$uri$is_args$args;
        proxy_no_cache $cookie_nocache $arg_nocache $arg_comment;
        proxy_no_cache $http_pragma $http_authorization;
        add_header  Nginx-Cache "$upstream_cache_status";  
        
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        include proxy_params;
    }    
}
6.大文件分片请求

http_slice_module

Syntax: slice size;
Default: slice 0;
Context:http,server,location
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值