nginx的expires 缓存设置

13 篇文章 0 订阅
9 篇文章 1 订阅

我的nginx中的配置

upstream django {
    # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
    server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name 144.48.66.*** ; # 你的服务器公网ip 或者 域名
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    location /static {
        alias /usr/local/test_project/static/; # static path
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     uwsgi_params; # the uwsgi_params file you installed
    }

    # 这里我给图片和JS, CSS 添加了过期时间,路径写你的静态文件路径
    location /usr/local/test_project/static/.*\.(jpg|jpeg|png|gif|icon)$
    {
        expires 30d;
    }

    location /usr/local/test_project/static/.*\.(js|css)?$
    {
        expires 10d;
    }

}

主要就是expires的值设置, 我这里设置的是30天和10天,因为更改的比较少,设置完之后的,访问一次网页后,对应的静态文件就存到了浏览器中,后面再次请求状态码就是304,也就是从缓存中获取文件

设置完后重启nginx生效, 建议平滑重启nginx (不会影响网站)

 

nginx 平滑重启

nginx -s reload

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值