Cache images on the Self-configured proxy server to save Internet traffic

Source: Internet
Author: User

In fact, you can install an Apache HTTP server on your computer, prepare it as a forward proxy, and then use the cache function to save traffic.

How to configure the forward proxy is not mentioned here. Catch the forward Command on the net. Many websites do not explicitly specify images or images ,. js /. css caches one end of time in your browser. switching between multiple pages of these websites will produce a lot of repeated traffic.

We can reasonably assume that the website images and. js/. css files will not change for a while. Therefore, we can configure Apache to modify the cache time of images and. js/. css files of these websites to avoid repeated transmission of the same files.

The configuration method is simple. In httpd. conf, open mod_headers, mod_mem_cache, mod_cache, mod_file_cache, and add the following Configuration:Copy codeThe Code is as follows: # local forward proxy server
Listen 5081.

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

Create a new text file, httpd-vhosts-5081.conf, In the conf/extra/directory (windows apache ). Add this configuration to this file (image files are cached for 365 days, and js/css files are cached for 1 hour ):

Copy codeThe Code is as follows: # 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>

Of course, you can also adjust the time parameter here, in seconds. You can use an Excel/calculator to calculate the required number of seconds in advance.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.