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

Compression function and cache time of apache web page optimization

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Apache web page optimization

Overview of Optimization

Compression function optimization

Configure the web page compression function of Apache, which uses the gzip compression algorithm to compress the web page content and then transfer it to the client browser.

First share the host's shared directory to [root@localhost] # smbclient-L / / 192.168.100.23 / # access the host's shared file Enter SAMBA\ root's password: OS= [Windows 10 Enterprise 17763] Server= [Windows 10 Enterprise 17763] Sharename Type Comment-ADMIN$ Disk Remote administration C$ Disk default share D$ Disk default share E$ Disk default share F$ Disk default share G$ Disk default share IPC$ IPC remote IPC LAMP Disk LAMP-C7 Disk share Disk Users Disk Connection to 192.168.100.23 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND) NetBIOS over TCP disabled-- no workgroup available [root@localhost ~] # mkdir / abc # create a mount point [root@localhost ~] # mount.cifs / / 192.168.100.23/LAMP-C7 / abc/ # mount Password for root@//192.168 .100.23/LAMP-C7: [root@localhost ~] # cd / abc [root@localhost abc] # ls # our source code packages are all in it apr-1.6.2.tar.gz Discuz_X2.5_SC_UTF8.zip mysql-5.6.26.tar.gzapr-util-1.6.0.tar.gz fiddler.exe php-5.6.11.tar.bz2awstats- 7.6.tar.gz httpd-2.4.29.tar.bz2cronolog-1.6.2-14.el7.x86_64.rpm LAMP-php5.6.txt decompression Move cronolog-1.6.2-14.el7.x86_64.rpm LAMP-php5.6.txt [root@localhost abc] # tar jxvf httpd-2.4.29.tar.bz2-C / opt # to [root@localhost abc] # tar zxvf apr-1.6.2.tar.gz-C / opt/ [root@localhost abc] # tar zxvf apr-util-1.6.0.tar.gz-C / opt/ [root@localhost abc] # cd / opt under OPT [root@localhost opt] # lsapr-1.6.2 apr-util-1.6.0 httpd-2.4.29 rh [root@localhost opt] # mv apr-1.6.2/ httpd-2.4.29/srclib/apr # move to this directory [root@localhost opt] # mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util [root@localhost opt] # lshttpd-2.4.29 rh installation environment package [ Root@localhost opt] # cd httpd-2.4.29 / calhost httpd-2.4.29] # yum-y install\ gcc\ gcc-c++\ make\ pcre-devel\ zlib-devel\ expat-devel\ pcre\ perl has been installed: gcc.x86_64 0buret 4.8.5-39.el7 gcc-c++.x86_64 0rig 4.8.5-39.el7 pcre-devel.x86_64 0rig 8.32- 17.el7 zlib-devel.x86_64 0VOR 1.2.7-18.el7 is installed as a dependency: cpp.x86_64 0VOR 4.8.5-39.el7 glibc-devel.x86_64 0VOR 2.17-292.el7 glibc-headers.x86_64 0Rover 2.17-292.el7 kernel-headers.x86_64 0Rover 3.10.0-1062.4 .1.el7 libmpc.x86_64 039.el7 1.0.1-3.el7 libstdc++-devel.x86_64 0vir 4.8.5-39.el7 upgraded as a dependency: glibc.x86_64 0rig 2.17-292.el7 glibc-common.x86_64 0vir 2.17-292.el7 libgcc.x86_64 0vir 4.8.5-39.el7 Libgomp.x86_64 0VOR 4.8.5-39.el7 libstdc++.x86_64 0RU 4.8.5-39.el7 zlib.x86_64 0RU 1.2.7-18.el7 over! Install Apache underlying function calhost httpd-2.4.29] #. / configure\-- prefix=/usr/local/httpd\ # specify the path-- enable-deflate\ # Compression function-- enable-so\ # Core Module on-- enable-rewrite\ # enable rewrite function Hotlink protection-enable-charset-lite\ # support character set-enable-cgi# Universal Gateway API compilation and installation [root@localhost opt] # make [root@localhost opt] # make installmkdir / usr/local/httpd/manualmake [1]: leave the directory "/ opt/httpd-2.4.29" [root@localhost httpd-2.4.29] # to make a soft link to the main configuration file to facilitate [root@localhost httpd-2.4. 29] # cd / usr/local/httpd/ [root@localhost httpd] # lsbin cgi-bin error icons lib man modulesbuild conf htdocs include logs manual [root@localhost httpd] # cd conf [root@localhost conf] # lsextra httpd.conf magic mime.types original [root@localhost conf] # ln-s / usr/local/httpd/conf/httpd.conf / etc/httpd.conf configuration main configuration file Listen 192.168.136.136 Viru 80 # enable listening address # Listen 80 # close the IPV6 listening address ServerName www.kgc.com:80 # turn on the domain name server LoadModule deflate_module modules/mod_deflate.so # in front # remove the enable function # add a paragraph at the end of the file AddOutputFilterByType DEFLATE text/html text/plain test/css test/xml test/javascript test/jpg test/png # support various types of files DeflateCompressionLevel 9 # 9 high compression ratio SetOutputFilter DEFLATE # default filter # check syntax Error [root@localhost conf] # / usr/local/httpd/bin/apachectl-tSyntax OK enabling service Check whether the port has been provided [root@localhost conf] # / usr/local/httpd/bin/apachectl start [root@localhost conf] # netstat-ntap | grep 80tcp 0 0192.168.136.136 ntap 80 0.0.0.0 ntap * LISTEN 52832/httpd [root@localhost htdocs] # cd / usr/local/httpd/ [root@localhost httpd] # cd bin/ [root@localhost bin] # systemctl Stop firewalld.service [root@localhost bin] # setenforce 0 to see if the compression module has been started [root@localhost bin] #. / apachectl-t-D DUMP_MODULES | grep "deflate" deflate_module (shared) into the host directory into an image to test

Want to see its compression function. Let's put a photo on the default web page and try [root@localhost abc] # cd / abc/ [root@localhost abc] # lsapr-1.6.2.tar.gz Discuz_X2.5_SC_UTF8.zip mysql-5.6.26.tar.gzapr-util-1.6.0.tar.gz fiddler.exe php-5.6.11.tar.bz2awstats-7.6.tar .gz httpd-2.4.29.tar.bz2 tu9892_14.jpg # this is our picture cronolog-1.6.2-14.el7.x86_64.rpm LAMP-php5.6.txt [root@localhost abc] # cp tu9892_14.jpg / usr/local/httpd/htdocs/ # copy this photo to the default home page [root@localhost abc] # cd / usr/local/httpd/htdocs/ [root@localhost htdocs] # Lsindex.html tu9892_ 14.jpg [root @ localhost htdocs] # vim index.htmlIt works!

Go to the client to test the compression function

Optimization of caching time of web pages

Configure Apache through the mod_expire module, make the web page cache in the client browser for a period of time, avoid repeated requests, reduce the access frequency and times of the client segment, and achieve the purpose of reducing unnecessary traffic and increasing access speed.

The previous steps are more compressed. Let's go directly to the main configuration file to open the cache module Listen 192.168.136.136 Listen 80 # enable the listening address # Listen 80 # turn off the IPV6 listening address ServerName www.kgc.com:80 # turn on the domain name server LoadModule expires_module modules/mod_expires.so # add ExpiresActive On # enable function ExpiresDefault "access plus 31104000 seconds" # Open caching time 31104000 0s verify syntax format There is no error [root@localhost conf] # cd / usr/local/httpd/ [root@localhost httpd] # cd bin/ [root@localhost bin] #. / apachectl-tSyntax OK enable the service to check whether the port has been provided [root@localhost bin] #. / apachectl start [root@localhost bin] # netstat-ntap | grep 80tcp 0 192.168.136.136min 80 0.0.0.0 * LISTEN 52832/httpd [root@localhost bin] # systemctl stop firewalld.service [root@localhost bin] # setenforce 0 check whether the cache module has been started [root@localhost bin] #. / apachectl-t-D DUMP_MODULES | grep "expires" expires_module (shared) go to the client segment to test it.

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