In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces Apache how to achieve web page compression and caching, the article introduces in great detail, has a certain reference value, interested friends must read it!
Apache web page optimization concept
In enterprises, only the default configuration parameters are used after the deployment of Apache, which will cause a lot of problems on the website. In other words, the default configuration is aimed at the previously low configuration.
Server configuration, the previous configuration is no longer suitable for today's Internet era, in order to meet the needs of enterprises, we need to consider how to improve the nature of Apache
Ability and stability, this is the content of Apache optimization.
Optimize content:
Configure web page compression
Configure web page caching time
Configure hotlink protection
Configure hidden version number
Gzip introduction
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.
Action
Reduces the number of bytes transmitted through the network and speeds up the loading speed of web pages.
Save traffic and improve users' browsing experience
Gzip has a better relationship with the crawling tool of search bow | engine.
The compression module of Apache the function modules of Apache to realize web page compression include
Mod_gzip module
Mod_deflate module
Apache 1.x
There is no built-in web page compression technology, but compression can be performed using the third E mod _ gzip module.
Apache 2.x
At the time of development, the module mod_deflate is built in to replace mod_gzip.
Mod_gzip module and mod_deflate module
Both of them use gzip compression algorithm, which works similarly.
Mod_deflate compression speed is slightly faster, while mod_gzip compression ratio is slightly higher.
Mod_gzip has a higher occupation of server CPU.
For high-traffic servers, mod_deflate may load faster than mod_gzip
Experiment on configuring Web Page Compression function
(1) share the toolkits we need at the host computer.
(2) Mount the toolkit to the Linux system through the Samba service.
[root@localhost ~] # smbclient-L / / 192.168.100.50 / / View share Enter SAMBA\ root's password: / / Anonymous share, no password Direct enter OS= [Windows 10 Enterprise LTSC 2019 17763] Server= [Windows 10 Enterprise LTSC 2019) Sharename Type Comment-IPC$ IPC remote IPC share Disk tools Disk Users Disk Connection to 192.168.100.50 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND) NetBIOS over TCP disabled-- no workgroup available [root@localhost ~] # mkdir / mnt/tools/ / create a mount directory [root@localhost ~] # mount.cifs / / 192.168.100.50/tools / mnt/tools/ mount Password for root@//192.168.100.50/tools: [root@localhost ~] # cd / mnt/tools/ enter the mount directory [root @ localhost tools] # ls / / View awstats-7.6.tar.gz extundelete-0.2.4.tar.bz2 forbid.png jdk-8u191-windows-x64.zip LAMP-C7cronolog-1.6.2-14.el7.x86_64.rpm fiddler.exe intellijideau2018.rar john-1.8.0.tar.gz picture.jpg [root@localhost tools] #
(3) decompress the compressed package that compiles and installs the Apache service to the "/ opt/" directory.
[root@localhost tools] # cd LAMP-C7/ switch directory [root@localhost LAMP-C7] # lsapr-1.6.2.tar.gz Discuz_X2.5_SC_UTF8.zip LAMP-php5.6.txt php-5.6.11.tar.bz2apr-util-1.6.0.tar.gz httpd-2.4.29.tar.bz2 mysql-5.6.26.tar.gz [root@localhost LAMP-C7] # tar jxvf httpd-2.4.29.tar.bz2-C / opt/ extract [root@localhost LAMP-C7] # tar zxvf apr-1.6.2.tar.gz-C / opt/ extract [root@localhost LAMP-C7] # tar zxvf apr-util-1.6.0.tar.gz-C / opt/ extract
(4) enter the "/ opt/" directory, move the two apr packages to the "httpd-2.4.29/srclib/" directory, and rename them.
[root@localhost LAMP-C7] # cd / 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 [root@localhost opt] # mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util
(5) go to the "httpd-2.4.29/" directory and install the environment package required for compilation.
[root@localhost opt] # lshttpd-2.4.29 rh [root@localhost opt] # cd httpd-2.4.29/ [root@localhost httpd-2.4.29] # lsABOUT_APACHE ap.d CHANGES docs httpd.spec libhttpd.dep Makefile.win README srclibacinclude.m4 build CMakeLists.txt emacs-style include libhttpd.dsp modules README.cmake supportApache-apr2 .dsw BuildAll.dsp config.layout httpd.dep INSTALL libhttpd.mak NOTICE README.platforms testApache.dsw BuildBin.dsp configure httpd.dsp InstallBin.dsp LICENSE NWGNUmakefile ROADMAP VERSIONINGapache_probes.d buildconf configure.in httpd.mak LAYOUT Makefile.in os server [root@localhost httpd-2.4.29] # [root@localhost httpd-2.4.29] # Yum-y install\ > gcc\ > gcc-c++\ > make\ > pcre\ > pcre-devel\ > expat-devel\ > zlib-devel\ > perl.// omits the installation process
(6) configure the Apache server.
[root@localhost httpd-2.4.29] #. / configure\ >-- prefix=/usr/local/httpd\ / / installation path >-- enable-deflate\ / / enable compression module support >-- enable-expires\ / enable cache module support >-- enable-so\ / / enable dynamic loading module support >-- enable-rewrite\ / / enable web address rewriting >-- enable-charset-lite\ / / enable character set support >-- enable-cgi / / enable CGI scripting support
(7) compile and install Apache service.
[root@localhost httpd-2.4.29] # make & & make install.// omits the compilation and installation process [root@localhost httpd-2.4.29] #
(8) modify the Apache service configuration file.
[root@localhost httpd-2.4.29] # ln-s / usr/local/httpd/conf/httpd.conf / etc/httpd.conf / / create a soft link Easy to use [root@localhost httpd-2.4.29] # [root@localhost httpd-2.4.29] # vim / etc/httpd.confListen 192.168.52.133 IPv4 80 / / enable IPv4 snooping # Listen 80 / / comment IPv6 snooping ServerName www.abc.com:80 / / set domain name LoadModule headers_module modules/mod_headers.so / / request header LoadModule deflate_module modules/mod_deflate.so / / enable compression module LoadModule filter_module modules/mod_filter.so / / filter by default, default enable / / tail add compression module information AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript text/jpg text/png / / enable compressed content DeflateCompressionLevel 9 / / compression level Level 9 SetOutputFilter DEFLATE / / enable deflate module to compress the output of this site with gzip
(9) check the configuration file format, the format is correct.
[root@localhost httpd-2.4.29] # / usr/local/httpd/bin/apachectl-tSyntax OK [root@localhost httpd-2.4.29] #
(10) move the "apachectl" file under the "/ usr/local/httpd/bin/" directory to the "/ etc/init.d/" directory, add the chkconfig recognition configuration at the beginning of the file, and then add it as a standard Linux system service.
[root@localhost httpd-2.4.29] # cp / usr/local/httpd/bin/apachectl / etc/init.d/httpd / / copy [root@localhost httpd-2.4.29] # vim / etc/init.d/httpd / / add two lines of declaration to the configuration file # chkconfig: 35 85 21 / / Service identification parameter Start at levels 3 and 5: the order of startup and shutdown is 85, 2 start description: Apache is a World Wide Web server / / Service description Information [root@localhost httpd-2.4.29] # chkconfig-- add httpd/ / add httpd service as a system service [root@localhost httpd-2.4.29] # [root@localhost httpd-2.4.29] # service httpd start / / start Apache service [root@localhost httpd-2.4.29] # ln-s / usr/local/httpd/bin/* / usr/local/bin/ transfer the command file of the Apache service Create a soft link to a directory that is easy for the system to recognize [root@localhost httpd-2.4.29] #
(11) check whether the module is installed successfully.
[root@localhost httpd-2.4.29] # apachectl-t-D DUMP_MODULES | grep "deflate" / / Verification module deflate_module (shared) [root@localhost httpd-2.4.29] # [root@localhost httpd-2.4.29] # systemctl stop firewalld.service / / turn off firewall [root@localhost httpd-2.4.29] # setenforce 0 / / turn off enhanced security features [root@localhost httpd-2.4.29] #
(12) copy the "picture.jpg" picture of the mount directory to the Apache service site directory "/ usr/local/httpd/htdocs/", and then add the picture to the home file.
[root@localhost httpd-2.4.29] # cd / mnt/tools/ switch directory [root@localhost tools] # lsawstats-7.6.tar.gz extundelete-0.2.4.tar.bz2 forbid.png jdk-8u191-windows-x64.zip LAMP-C7cronolog-1.6.2-14.el7.x86_64.rpm fiddler.exe intellijideau2018.rar john-1.8. 0.tar.gz picture.jpg [root@localhost tools] # cp picture.jpg / usr/local/httpd/htdocs/ copy the picture [root@localhost tools] # cd / usr/local/httpd/htdocs/ change the directory [root@localhost htdocs] # ls / / View index.html picture.jpg [root@localhost htdocs] # vim index.html / / Edit the home page file It works!
(13) install the package grabbing tool fiddler on the win10 host.
(14) visit the Apache website on the win10 host.
(15) if you check the contents of the captured package, you can see that the image has been compressed by gzip in Headers.
Cache module of Apache
Configure Apache through the mod_expire module, so that the web page can be cached in the client browser for a period of time, in order to avoid repeated requests to enable the mod_expire module, it will automatically generate Expires tags and Cache-Control tags in the page header information, thus reducing the frequency and times of client access, reducing unnecessary traffic and increasing access speed.
Experiment on configuring Web Page caching time
(1) following the above experiment, the cache module was added when configuring the Apache service. So modify the Apache configuration file directly.
[root@localhost htdocs] # vim / etc/httpd.confLoadModule expires_module modules/mod_expires.so / / enable cache module / / tail add cache module information ExpiresActive On / / cache enable ExpiresDefault "access plus 50 seconds" / / cache time 50 seconds
(2) check the Apache configuration file format, the format is correct.
[root@localhost htdocs] # apachectl-tSyntax OK [root@localhost htdocs] #
(3) restart the service and view the listening port
[root@localhost htdocs] # service httpd stop / / disable the service [root@localhost htdocs] # service httpd start / / enable the service [root@localhost htdocs] # [root@localhost htdocs] # netstat-ntap | grep 80 / / check the listening port tcp 0 0192.168.52.133 LISTEN 83296/httpd [root@localhost htdocs] #
(4) check whether the cache module is installed successfully.
[root@localhost htdocs] # apachectl-t-D DUMP_MODULES | grep "expires" / / Verification module expires_module (shared) [root@localhost htdocs] #
(5) visit the Apache site again with the win10 host.
(6) check the capture package. You can see that the cache time is 50 seconds in Headers.
(7) We change the cache time in the Apache service profile to 30 seconds, and then restart the service.
[root@localhost htdocs] # vim / etc/httpd.conf ExpiresActive On ExpiresDefault "access plus 30 seconds" / / change 50 to 30 [root@localhost htdocs] # service httpd stop / / close the service [root@localhost htdocs] # service httpd start / / start the service [root@localhost htdocs] #
(8) use the win10 host to access the Apache service site again.
(9) check the capture package. In Headers, you can see that the cache time has changed from 50 seconds to 30 seconds.
The above is all the contents of the article "how to achieve web page compression and caching in Apache". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.