用户名:
密 码: 记住
您当前的位置:首页 > 站长百科 > 服务器技术

自设代理服务器缓存图片节省上网流量

时间:2015-01-18  来源:互联网  作者:佚名
其实可以在电脑上安装一个 Apache HTTP server, 配制成 forward proxy, 然后使用其中的缓存功能来节省流量。

怎么样配置 forward proxy 这里不多说,网上一抓一大把。这里讲的是,有很多网站并没有明确指明图片、.js/.css 在用户的浏览器里面缓存一端时间,在这些网站的多个页面中切换,就会产生很多的重复流量。

我们可以合理地假定,网站的图片、.js/.css 文件,在一段时间内是不会变的。因此我们可以配置 Apache 修改这些网站的 图片、.js/.css 文件缓存时间,避免重复传输同样的文件。

配置方法很简单,在 httpd.conf 中,打开 mod_headers, mod_mem_cache, mod_cache, mod_file_cache, 加上以下配置:
. 代码如下:
#local forward proxy server
Listen 5081

Include conf/extra/httpd-vhosts-5081.conf



新建一个文本文件, httpd-vhosts-5081.conf, 放在conf/extra/ 目录中(windows版本 apache)。在此文件中,加上这样的配置(图片文件缓存 365 天,js/css 缓存 1 小时):


. 代码如下:
#local forward proxy server
NameVirtualHost *:5081

#local forward proxy server
<VirtualHost *:5081>
ProxyRequests On
ProxyVia On
<LocationMatch "\.(js|css)$">
Header unset P3P
Header unset Cache-Control
Header unset Expires
Header unset Pragma
Header unset ETag
FileETag None

#cache 1 hour
Header set Cache-Control "max-age=3600, public"
</LocationMatch>

<LocationMatch "\.(gif|jpe?g|png)$">
Header unset P3P
Header unset Cache-Control
Header unset Expires
Header unset Pragma
Header unset ETag
FileETag None

#cache 365 days
Header set Cache-Control "max-age=31536000, public"
</LocationMatch>

</VirtualHost>


当然了,也可以调整这里的时间参数,单位为秒。可以用 Excel/计算器事先计算好需要的秒数。
来顶一下
返回首页
返回首页
推荐资讯
【图文教程】dede织梦网站后台如何发表文章? 【图文教程】dede织梦网站后台如何对于新手站长可能不了解,dede织梦后台是如何发文章的。下面
2014站长圈十大事件:PR已死 移动算法兴起 2014站长圈十大事件:PR已死 移动算2014年即将过去,虽然站长圈相比过去几年稍显沉寂,但&ldquo
相关文章
    无相关信息
栏目更新
栏目热门