Apache Performance Optimization

Source: Internet
Author: User
Tags browser cache website performance

Http://weizhifeng.net/high-performance-with-apache.html

Objective

Apache is the most widely used Web server in the world, and according to the rules of pagespeed, we can adjust it from keepalive, browser cache, gzip, etc. to improve website performance.


Open keep-alive

When Keep-alive is turned on, you can ensure that the connection between the browser and the server persists, so that if the same domain name requests a lot of resources, you can eliminate the time and resource consumption of establishing a connection. Therefore, for the static server, because a domain name will request n more resources, it is better to open keep-alive, but for dynamic servers, it is not appropriate to open keep-alive, because this will cause a lot of idle process, wasting memory space. Configuration:

KeepAlive on #开启KeepAlive
KeepAliveTimeout 5 #保持连接5秒


HTTP Cache Settings

When you enter a URL directly in the browser, or click a link, then the browser cache will work, if the cache does not expire, then the browser will read from the local resources, do not initiate an HTTP request, if the cache expires, then the browser will initiate a new browser request. By pressing Ctrl+f5, the browser empties the local cache and requests the resource again.
Expires is the http/1.0 cache header, Cache-control:max-age is the header that http/1.1 is used for HTTP caching.
expires specifies the absolute time for resource expiration, GMT format, and cache-control:max-age specifies the relative time, in seconds, for resource expiration.
On browsers that support http/1.1, if you send two headers, the Cache-control:max-age will overwrite the expires;
On a browser that supports http/1.0, even if two headers are sent, only expires will work, so in order to be compatible with the old browser, you should send these two headers at the same time.

Setting the HTTP cache requires the installation of Expires_module, which sends expires and Cache-control:max-age two HTTP headers. The configuration is as follows:

<ifmodule expires_module>
Expiresactive on
Expiresbytype application/x-javascript "Access Plus"
Expiresbytype text/css "Access Plus"
Expiresbytype image/gif "Access Plus"
Expiresbytype image/jpeg "Access Plus"
Expiresbytype image/png "Access Plus"
</IfModule>

Expiresbytype application/x-javascript "Access plus days" means setting the expires and Cache-control:max-age headers on the JS resource, Where the value of expires is 30 days after the client accesses the resource's time, the Cache-control:max-age value is 3600x24x30 seconds.
Expiresbytype application/x-javascript "Modification Plus" is the same as above, but the expires time is based on the last time the resource was modified as a benchmark.


turn on gzip compression and set the vary header

Gzip compresses the text resources, generally saving 40% of the size, binary content does not need to turn on gzip compression, because these files are already compressed, if the gzip compression will increase its size. Static resources are generally cached on the proxy server, while some browsers support gzip, but there are older browsers that do not support gzip, so you need to set the vary:accept-encoding header, which tells the proxy cache server to cache two copies of the resource, one compressed, A copy that has not been compressed and then returns compressed or uncompressed content based on the accept-encoding header sent by the browser. To set up gzip compression, you need to install Deflate_module. The configuration is as follows:

<ifmodule deflate_module>
#对js, html,xml,css, normal text open gzip compression
Addoutputfilterbytype DEFLATE application/x-javascript text/html text/plain text/xml text/css
</IfModule>


Turn off the etag.

Last-modified and ETag are the same function, are used to identify whether a resource has changed, last-modified value is the time stamp of the resource, if press F5 or Refresh button if-modified-since header will be sent to the server with a timestamp, If the last modification time of the resource on the server <= this time, then return 304 not Modified, otherwise return a new resource with a value of OK, and the etag is a string calculated from the information of the resource (typically inode, size, timestamp). If you press F5 or refresh button The If-none-match header will be sent to the server with this value, the server uses this value to match the value of the current resource, if it is equal, return 304 not Modified, otherwise return a new resource and OK. By default, Apache sends Last-modified and etage to static resources, but because the etage computation consumes the CPU resources of the server, select Turn off and turn on last-modified only. Configuration:

Fileetag None
Header unset ETag

Apache Performance Optimization

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.