zoukankan      html  css  js  c++  java
  • 配置Nginx网页缓存时间!

    当 Nginx 将网页数据返回给客户端后,可设置缓存的时间,以方便在日后进行相同内容
    的请求时直接返回,以避免重复请求,加快了访问速度,一般针对静态网页进行设置,对动
    态网页不用设置缓存时间。可在 Windows 客户端中使用 fiddler 查看网页缓存时间。
    设置方法:
    在 可修改配置文件,在 http 段、或 server 段、或者 location 段加入对特定内容的过期参
    数。

    ====================================================================

    [root@localhost html]# vim /etc/nginx.conf 

    复制代码
    
    

    user nginx nginx;
    worker_processes 2;

    
    

    error_log logs/error.log;
    error_log logs/error.log info;

    
    

    pid logs/nginx.pid;

    
    


    events {
           use epoll;
           worker_connections 10240;
    }

    http {
          include mime.types;
          default_type application/octet-stream;

    
    

           log_format main '$remote_addr - $remote_user [$time_local] "$request" '
           '$status $body_bytes_sent "$http_referer" '
            '"$http_user_agent" "$http_x_forwarded_for"';

    
    

              access_log logs/access.log main;
             sendfile on;
             server_tokens off;
             keepalive_timeout 65;

    
    

    server {
            listen 80;

            server_name localhost;

             charset utf-8;


    location / {
             root html;
             index index.html index.htm;
    }
    location ~* .(gif|jpg|jpeg|bmp|ico)$ {               //如果是这种类型的文件缓存时间为一天
            expires 1d;
    }
    location ~* .(js|css)$ {                            //如果是js或css类型的文件缓存为一小时
           expires 1h;
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
         }

       }

    }

    复制代码

    [root@localhost nginx-1.16.0]# cd
    [root@localhost ~]# cd /usr/local/nginx/html/

    导入图片
    [root@localhost html]# rz
    z waiting to receive.**B0100000023be50
    [root@localhost html]# ls
    50x.html index.html linux.jpg

    [root@localhost html]# vim index.html

    在尾部添加如下代码:

    <p><em>Thank you for using nginx.</em></p>
    <img src='linux.jpg'/>
    </body>
    </html>
    ~                 

    [root@localhost html]# killall -s HUP nginx                           //重启配置

     

  • 相关阅读:
    Html5 Input 类型
    Html5 部分特性
    Asp.net Mvc4 基于Authorize实现的模块访问权限
    第11天知识点总结
    C# string类型和byte[]类型相互转换
    C#中AppDomain.CurrentDomain.BaseDirectory及各种路径获取方法
    Socket 学习
    C#中的Dictionary字典类介绍
    js判断客户端是pc还是手机
    input type="file" accept="image/*"上传文件慢的问题解决办法
  • 原文地址:https://www.cnblogs.com/L1-5551/p/11518553.html
Copyright © 2011-2022 走看看