Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Apache setting Compression and caching in Linux

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you the content of sample analysis of Apache compression and caching in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Compress the file:

Edit apache module

Vim / etc/httpd/conf.modules.d/00-base.conf

Make sure the following three modules are not commented

LoadModule headers_module modules/mod_headers.so

LoadModule deflate_module modules/mod_deflate.so

LoadModule filter_module modules/mod_filter.so

Note: you can also put three modules in the / etc/httpd/conf/httpd.conf file. Modules can only be loaded in one file.

Set compression rules

Vim / etc/httpd/conf/httpd.conf

Add at the end

AddOutputFilterByType DEFLATE application/javascript

AddOutputFilterByType DEFLATE application/rss+xml

AddOutputFilterByType DEFLATE application/vnd.ms-fontobject

AddOutputFilterByType DEFLATE application/x-font

AddOutputFilterByType DEFLATE application/x-font-opentype

AddOutputFilterByType DEFLATE application/x-font-otf

AddOutputFilterByType DEFLATE application/x-font-truetype

AddOutputFilterByType DEFLATE application/x-font-ttf

AddOutputFilterByType DEFLATE application/x-javascript

AddOutputFilterByType DEFLATE application/xhtml+xml

AddOutputFilterByType DEFLATE application/xml

AddOutputFilterByType DEFLATE application/x-httpd-php

AddOutputFilterByType DEFLATE application/x-httpd-fastphp

AddOutputFilterByType DEFLATE font/opentype

AddOutputFilterByType DEFLATE font/otf

AddOutputFilterByType DEFLATE font/ttf

AddOutputFilterByType DEFLATE image/svg+xml

AddOutputFilterByType DEFLATE image/x-icon

AddOutputFilterByType DEFLATE text/css

AddOutputFilterByType DEFLATE text/html

AddOutputFilterByType DEFLATE text/javascript

AddOutputFilterByType DEFLATE text/plain

AddOutputFilterByType DEFLATE text/xml

# Remove browser bugs (only needed for really old browsers)

BrowserMatch ^ Mozilla/4 gzip-only-text/html

BrowserMatch ^ Mozilla/4\ .0 [678] no-gzip

BrowserMatch\ bMSIE! no-gzip! gzip-only-text/html

# SetEnvIfNoCase Request_URI. (?: gif | jpe?g | png) $no-gzip dont-vary # set not to compress the picture file with the suffix gif,jpg,jpeg,png

Header append Vary User-Agent

The compression ratio is generally greater than 70%.

Compression ratio detection (http://tool.chinaz.com/Gzips/) can only be detected on the PC side

Set up the cache:

Vim / etc/httpd/conf.modules.d/00-base.conf

Make sure the following modules are not commented

LoadModule headers_module modules/mod_headers.so # the first caching method

LoadModule expires_module modules/mod_expires.so # the second caching method

Note: you can also put this module in the / etc/httpd/conf/httpd.conf file. The module can only be loaded in one file.

Set caching rules

Vim / var/www/html/.htaccess

Add at the end

The first caching method

FileEtag INode Mtime Size

The second way of caching

# the cache is valid for 1 month

Header set Cache-Control "max-age=2592000, public"

Header set Cache-Control "max-age=2592000, public, must-revalidate"

Note: max-age is the cache time (in seconds) and can be modified as needed.

The third way of caching

Vim / etc/httpd/conf/httpd.conf

Add the following

ExpiresActive On

# css file cache 2592000 Universe 3600Universe 24 January

ExpiresByType text/css A2592000

# js file cache 2592000 Universe 3600Universe 24 January

ExpiresByType application/x-javascript A2592000

ExpiresByType application/javascript A2592000

# html file cache 2592000 Universe 3600Universe 24 January

ExpiresByType text/html A2592000

# Image file cache 2592000 Universe 3600Universe 24th January

ExpiresByType image/jpg A2592000

ExpiresByType image/jpeg A2592000

ExpiresByType image/gif A2592000

ExpiresByType image/png A2592000

ExpiresByType image/ico A2592000

ExpiresByType image/x-icon A2592000

# File default cache January

ExpiresDefault "access plus 30 days"

Note: choose one of the three ways mentioned above

Restart the apache service

Service httpd restart

Note: apache setting compression and caching will increase the memory pressure on the server, but after setting compression and caching, the website access speed will be improved.

Thank you for reading! This is the end of this article on "sample analysis of compression and caching of Apache settings in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report