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

Optimization and configuration of Apache Services-static Resource Compression and caching

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Optimization and configuration of Apache Services-static Resource Compression and caching

Based on the previous log file segmentation and log file analysis, this time will bring you the compression of Apache static resources and the setting of cache time.

This experiment uses software package collection: link: https://pan.baidu.com/s/1Ag3Sns8iH-J9W8cdtfjPPg Please add link description extraction code: qcog

1. Static resource compression optimization purpose:

Although an original image does not take up much server resources, but once the highly concurrent tasks are carried out, the static resources (such as pictures, etc.) will not be compressed, which will bring great pressure to the server.

Optimization steps:

1. Compile and install Apache manually

[root@localhost ~] # mount.cifs / / 192.168.10.181/LAMP-C7 / mnt / / remotely mount the software package [root@localhost] # cd / mnt [root@localhost mnt] # tar xjvf httpd-2.4.29.tar.bz2-C / opt/ [root@localhost mnt] # tar zxf apr-1.6.2.tar.gz-C / opt/ [root@localhost mnt] # tar zxf apr-util-1.6.0.tar. Gz-C / opt/ [root@localhost mnt] # cd / opt/ [root@localhost opt] # mv apr-1.6.2/ httpd-2.4.29/srclib/apr [root@localhost opt] # mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util [root@localhost opt] # cd httpd-2.4.29/ [root@localhost httpd-2.4.29] # yum install\ / / Install the environment package gcc\ gcc-c++\ pcre\ pcre-devel\ zlib-devel\ expat-devel-y [root@localhost httpd-2.4.29]. / configure\-- prefix=/usr/local/httpd\-- enable-so\-- enable-deflate\-- enable-expires\-- enable-rewrite\-- enable-charest-lite\-- enable-cgi [root@localhost httpd-2.4.29] # make & & make install / / compile & compile and install

2. Configure the http master configuration file

[root@localhost httpd-2.4.29] # cd / usr/local/httpd/ [root@localhost httpd] # vim conf/httpd.conf / / configuration main configuration file is in the configuration file. Search `/ LoadModule deflate_ `LoadModule deflate_ module modules/mod_ deflate.so / / to open it. Delete the # symbol in the header and save wq to exit the search `/ Listen`, set the listening address Listen 192.168.116.145 Listen 80 # # set the listening address # Listen 80 search` / ServerName`, set the domain name ServerName www.kgc.com:80 # # set the domain name to search `/ headers` and` / headers` respectively Open the corresponding module LoadModule deflate_module modules/mod_deflate.so # # enable the compression module LoadModule headers_module modules/mod_headers.so # # enable the header module to locate the last line by G Add LoadModule filter_module modules/mod_filter.so AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml test/javascript text/jpg text/png # # support compression type DeflateCompressionLevel 9 # # High compression ratio SetOutputFilter DEFLATE # # default filter load wq save exit

3. Start the service and edit the site

[root@localhost httpd] # cd / usr/local/httpd/bin/ [root@localhost bin] #. / apachectl start / / enable the service [root@localhost bin] # netstat-atnp | grep "80" [root@localhost bin] # cd / usr/local/httpd/htdocs / / enter the http default site [root@localhost htdocs] # vim index.html / / a pair of web pages to edit It works!

# # put the picture on the web page Note: the picture needs to be placed on the site in advance

4. Result verification

Configure the caching time of the web page through the mod_expire module to configure Apache. The web page can be cached in the client browser for a period of time to avoid repeated requests. After enabling the mod_expire module, the Expires tag and Cache-Control tag in the page header information will be generated automatically, thus reducing the frequency and frequency of client access, reducing unnecessary traffic and increasing access speed.

PS: this experiment is based on the above experiment.

1. Configure the main configuration file

[root@localhost httpd] # vim / conf/http.conf search `/ LoadModule expires_`, enable module LoadModule expires_module modules/ mod_expires.so / / enable cache module press G to locate the last line ExpiresActive On ExpiresDefault "access plus 10 seconds" / / set 10s cache wq save exit

2. Start the service

[root@localhost httpd] # cd bin/ [root@localhost bin] #. / apachectl start / / enable the service [root@localhost bin] # systemctl stop firewalld.service [root@localhost bin] # setenforce 0 [root@localhost bin] #. / apachectl-t-D DUMP_MODULES | grep "expires" / / View the opening status of the module expires_module (shared)

3. Result verification

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