当前位置:网站首页>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
边栏推荐
- My two-year persistence is worth it!
- How to solve domain name redirection? How to avoid such problems?
- At the beginning of the school season, use this template to improve the management level
- Material production tool manual
- How to use ffmpeg one frame H264 to decode yuv420p in audio and video development?
- TensorFlow 2 quickstart for beginners
- How to solve the problem that easynvr calls the video download interface of the specified time period to display "being synthesized" and does not generate video?
- Skips allowed on SAP QM material master inspection type
- Risc-v instruction set explanation (7) instruction address alignment and addition and subtraction overflow processing
- Test development knowledge map
猜你喜欢
![[fault announcement] one stored procedure brings down the entire database](/img/7c/e5adda73a077fe4b8f04b59d1e0e1e.jpg)
[fault announcement] one stored procedure brings down the entire database

Technology is a double-edged sword, which needs to be well kept

Solution to the 39th weekly game of acwing

One line of keyboard

What is the difference between a white box test and a black box test

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

ServiceStack. Source code analysis of redis (connection and connection pool)
随机推荐
Test development knowledge map
[industry outlook] future development forecast of UHD video application
A high-end router antenna connection mechanism that can simultaneously deploy and store antennas
Optimized the search function of broken websites
5 minutes, online from 0 to 1!
Feign request return value inverse sequence localdatetime exception record
Collateral damage from DDoS and hacktivism
How to register a domain name? What are the benefits of building a website?
At the beginning of the school season, use this template to improve the management level
Multi objective Optimization Practice Based on esmm model -- shopping mall
Is IPFs a new national infrastructure project? What impact will the new infrastructure have on IPFs?
The company is worried about customer frustration and brand damage caused by DDoS Attacks
From home to Ali, a year for junior students to apply for jobs
Install and use juicefs storage on Tencent cloud
Member management system PC side building tutorial (I)
Material production tool manual
"Adobe international certification" design white must understand the color theory, absolutely full of dry goods
Network Overview
Continuously evolving cloud native application delivery
Solution to the 39th weekly game of acwing