ATS+NIGNX 验证缓存(二) --配置源站nginx 缓存时间

打开 nginx 配置文件: vim nginx.conf,编辑:

http {
    include       mime.types;
    default_type  application/octet-stream;
    add_header    Cache-Control max-age=300;                                                  //添加这样的代码
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

保存后退出!然后验证

[root@nginx sbin]# ./nginx -t                                                                        //检查配置文件, -t   : test configuration and exit
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

测试验证,成功!

[root@nginx sbin]# curl -I "http://192.168.202.130/icon.png"
HTTP/1.1 200 OK
Server: nginx/1.10.1
Date: Mon, 25 Jul 2016 11:02:34 GMT
Content-Type: image/png
Content-Length: 8133
Last-Modified: Fri, 15 Jul 2016 09:01:24 GMT
Connection: keep-alive
ETag: "5788a664-1fc5"
Cache-Control: max-age=300                                                                      // nginx设置的header: cache-control 生效!
Accept-Ranges: bytes

然后验证缓存服务器ATS的Cache-Control信息:

[root@nginx ~]# curl -I "HTTP://192.268.202.129/icon.png"
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 25 Jul 2016 04:35:08 GMT
Content-Type: text/html
Content-Length: 164
Last-Modified: Wed, 25 Mar 2015 09:33:00 GMT
Connection: close
Accept-Ranges: bytes

通过ATS服务器进行从NGINX下载测试文件发现并没有Cache-Control头信息

[root@nginx ~]# curl -I "http://192.168.202.129/icon.png"
HTTP/1.1 200 OK
Server: ATS/6.1.1
Date: Mon, 25 Jul 2016 15:24:48 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Thu, 21 Jul 2016 18:01:48 GMT
ETag: "57910e0c-264"
Accept-Ranges: bytes
Age: 6710
Connection: keep-alive
Via: http/1.1 bi (ApacheTrafficServer/6.1.1)

 

posted @ 2016-07-25 11:14  su_yang  阅读(2083)  评论(0编辑  收藏  举报