当前位置:网站首页>Linux Apache setting compression and caching
Linux Apache setting compression and caching
2022-06-24 06:15:00 【User 1685462】
Compressed files :
edit apache modular
vim /etc/httpd/conf.modules.d/00-base.conf
Make sure that the following three modules are not annotated
LoadModule headers_module modules/mod_headers.so LoadModule deflate_module modules/mod_deflate.so LoadModule filter_module modules/mod_filter.so
Be careful : You can also put three modules into /etc/httpd/conf/httpd.conf In the document , Modules can only be loaded in one file
Set compression rules
vim /etc/httpd/conf/httpd.conf
Add... At the end
<IfModule mod_deflate.c> 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 # The suffix is not set gif,jpg,jpeg,png The image file is compressed Header append Vary User-Agent </IfModule>
The compression ratio is generally greater than 70%
Compression ratio detection (http://tool.chinaz.com/Gzips/) Only in pc End detection
Set the cache :
vim /etc/httpd/conf.modules.d/00-base.conf
Make sure that 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 cache method
Be careful : You can also put this module into /etc/httpd/conf/httpd.conf In the document , Modules can only be loaded in one file
Set cache rules
vim /var/www/html/.htaccess
Add... At the end
The first caching method
FileEtag INode Mtime Size
The second cache method
# Cache effective time 1 month <FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css)$"> Header set Cache-Control "max-age=2592000, public" </FilesMatch> <FilesMatch "\.(html|txt|htm|php)$"> Header set Cache-Control "max-age=2592000, public, must-revalidate" </FilesMatch>
Be careful :max-age For cache time , Unit second , Modify as needed
The third caching method
vim /etc/httpd/conf/httpd.conf
Add the following
<IfModule expires_module> ExpiresActive On #css File cache 2592000/3600/24=1 month ExpiresByType text/css A2592000 #js File cache 2592000/3600/24=1 month ExpiresByType application/x-javascript A2592000 ExpiresByType application/javascript A2592000 #html File cache 2592000/3600/24=1 month ExpiresByType text/html A2592000 # Picture file cache 2592000/3600/24=1 month 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 1 month ExpiresDefault "access plus 30 days" </IfModule>
Be careful : Above way , Choose one of three
restart apache service
service httpd restart
Be careful :apache Setting compression and caching will increase the memory pressure of the server , But after setting up compression and caching , The access speed of the website will be improved
边栏推荐
- At the trusted cloud conference, Tencent securely unlocked a number of new certifications!
- The influence of TLS protocol and cipher on remote RDP
- Optimized the search function of broken websites
- CLB unable to access / access timeout troubleshooting
- How is a Clickhouse query completed?
- Script updates CLB type ingress Certificate in tke cluster
- How to bind the most formal domain name? What are the precautions for binding domain names?
- Enterprise management background user manual
- Clickhouse alter table execution process
- Several relations to be clarified in the process of digital transformation: stock and increment
猜你喜欢

ServiceStack. Source code analysis of redis (connection and connection pool)

One line of keyboard

Technology is a double-edged sword, which needs to be well kept
![[fault announcement] one stored procedure brings down the entire database](/img/7c/e5adda73a077fe4b8f04b59d1e0e1e.jpg)
[fault announcement] one stored procedure brings down the entire database

Solution to the 39th weekly game of acwing

A cigarette of time to talk with you about how novices transform from functional testing to advanced automated testing

What is the difference between a white box test and a black box test
随机推荐
TensorFlow 2 quickstart for beginners
Spirit information development log (4)
A letter from little potato
Feign request return value inverse sequence localdatetime exception record
Enterprise management background user manual
Material production tool manual
Royal treasure: an analysis of SQL algebra optimization
PMP | 8 abilities that excellent project managers focus on training
Nature Neuroscience: challenges and future directions of functional brain tissue characterization
Summary of basic notes of C language (I)
Micro build low code supports Excel to import data source
Excellent tech sharing | research and application of Tencent excellent map in weak surveillance target location
Analysis on the influence of "network security policy issued successively" on Enterprises
Continuously evolving cloud native application delivery
As a sigmastar agent, Qiming cloud shares dry goods for you: what are the characteristics of ssd201/202
Rhel8 series update image Yum source is Tencent cloud Yum source
Overview of related concepts of social network analysis
Introduction of frequency standard comparison measurement system
25 classic selenium automated interview questions, collect them quickly
Increase the dynamic port range to solve TCPIP alarm