Kích hoạt nén Gzip trên Apache

0
2292

Bật Nén Gzip cho website sẽ giúp cho web của bạn load với tốc độ nhanh hơn rất nhiều lần. Và giảm được khoảng 70% dung lượng của web khi mở bằng trình duyệt
Với dịch vụ Apache , bạn có thể thực hiện bật nén Gzip như sau:

B1: Thêm module vào cấu hình Apache (httpd.conf)
Sử dụng lệnh : vi /etc/httpd/conf/httpd.conf
Thêm dòng sau : LoadModule deflate_module modules/mod_deflate.so

B2: Thêm đoạn mã sau vào httpd.conf
# mod_deflate configuration
<IfModule mod_deflate.c>

# Restrict compression to these MIME types
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css

# Level of compression (Highest 9 – Lowest 1)
DeflateCompressionLevel 9

# Netscape 4.x has some problems.
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

</IfModule>

B3 : restart lại dịch vụ apache
Sử dụng lệnh : service httpd restart

Kiểm tra nén Gzip đã được kích hoạt thành công chưa, các bạn có thể truy cập https://checkgzipcompression.com/

Leave a Reply

avatar
  Subscribe  
Notify of