Solution to Apache mod_deflate compression module bug

Source: Internet
Author: User

Apahce uses the mod_deflate compression module. Each time the client (such as a browser) retrieves data from the server (ps: Expires is not expired), the status code of the http request header is always 200, instead of 304 Not Modified.

304 Not Modified?

If the client sends a GET request with a condition and the request has been allowed, and the content of the document (since the last access or according to the condition of the request) has not changed, the server should return this status code. 304 the response is forbidden to contain the message body (which saves bandwidth and overhead). Therefore, it always ends with the first blank line after the message header.

Problem

F5 refresh. The status is always 200, as shown in the figure below:

This is a bug in Apahce itself. Apache uses gzip compression and cache at the same time, and the etag name is automatically changed to "******-gzip". Problems may occur when gzip exists.

Solution

If you use OneinStack and lnmp one-key installation package (ps: The latest download has solved this problem) and select lamp mode, the compression function is automatically enabled, you need to solve this problem as follows:

Put the last few lines of the file/usr/local/apache/conf/httpd. conf:
ServerTokens ProductOnly
ServerSignature Off
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript
DeflateCompressionLevel 6
SetOutputFilter DEFLATE
Include conf/vhost/*. conf

Replace:

<IfModule mod_headers.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript
<FilesMatch "\. (js | css | html | htm | png | jpg | swf | pdf | shtml | xml | flv | gif | ico | jpeg) $">
RequestHeader edit "If-None-Match" "^ (. *)-gzip (. *) $" "$1 $2"
Header edit "ETag" "^ (. *)-gzip (. *) $" "$1 $2"
</FilesMatch>
DeflateCompressionLevel 6
SetOutputFilter DEFLATE
</IfModule>
ServerTokens ProductOnly
ServerSignature Off
Include conf/vhost/*. conf
Restart apache:
Service httpd restart

Test

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.