In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Overview of Apache Web Page Optimization
In an enterprise, when Apache is deployed, only the default configuration parameters are used, which will
Cause a lot of problems on the website, in other words, the default configuration is aimed at the previously low
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.
Gzip introduction
■ configures Apache's web page compression function, which uses the gzip compression algorithm to
The content of the web page is compressed and then transferred to the client browser
■ action
● reduces the number of bytes transmitted over the network and speeds up the loading of web pages.
● saves traffic and improves users' browsing experience
● gzip has a better relationship with search engine crawling tools.
The functional modules of Apache to realize web page compression include
Mod_gzip module
Moddeflate module
Apache 1.x
● does not have built-in web page compression technology, but can use third-party mod gzip modules to perform compression
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 ● and ● use the gzip compression algorithm, which works similarly.
The compression speed of ● mod deflate is slightly faster, while the compression ratio of mod_gzip is slightly higher. Mod_gzip takes up more server CPU.
For high-traffic servers, using mod_deflate may load faster than mod_gzip
Degrees are faster
Configure web page compression
First check if the mod_deflate module is installed
● executes the apachectl-t-D DUMP_MODULES command
● if there is no deflate_module (static) in the output, it is not installed at compile time
Mod_deflate module
If there is no installation, recompile the installation
●. / configure-- enable-deflate...
● make & & make install
■ is configured in the configuration httpd.conf to enable the gzip function
● AddOutputFilterByType DEFLATE texthtml text/plain text/css
Text/xml text/javascript
● DeflateCompressionL evel
● SetOutputFilter DEFL ATE
The first line of ■ represents what kind of content gzip compression is enabled for
The second line of ■ represents the compression level
The third line of ■ represents enabling the deflate module to compress the output of this site with gzip.
Apache compression operation installs Apache service
Remotely mount the package folder locally and view
[root@localhost ~] # mkdir / abc/ / create mount point [root@localhost ~] # mount.cifs / / 192.168.100.7/LAMP-C7 / abc/ mount Password for root@//192.168.100.10/LAMP-C7: [root@localhost ~] # cd / abc/ [root@localhost abc] # lsapr-1.6.2.tar.gz Cronolog-1.6.2-14.el7.x86_64.rpm LAMP-php5.6.txtapr-util-1.6.0.tar.gz Discuz_X2.5_SC_UTF8.zip mysql-5.6.26.tar.gzawstats-7.6.tar.gz httpd-2.4.29.tar.bz2 php-5.6.11.tar.bz2
Extract the source code package to the / opt directory and move the httpd package
[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] # tar jxvf httpd-2.4.29.tar.bz2-C / opt/ [root@localhost abc] # cd / opt/ [root@localhost opt] # lsapr-1.6.2 apr-util-1.6.0 httpd-2.4.29 httpd. Txt rh [root@lamp opt] # mv apr-1.6.2/ httpd-2.4.29/srclib/apr [root@lamp opt] # mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util
Install the necessary software packages for the lab environment
Yum-y install\ gcc\ gcc-c++\ make\ pcre-devel\ zlib-devel\ expat-devel\ pcre\ perl
Configure installation directories and modules
[root@lamp opt] # cd / opt/httpd-2.4.29/./configure\-prefix=/usr/local/httpd\-- enable-so\-- enable-deflate\-- enable-expires\-- enable-rewrite\-- enable-charset-lite\-- enable-cgi
Compile and install Apache
Make & & make install modifies the Apache configuration file [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] # vim httpd.conf [root@localhost conf] # ln-s / usr/local/httpd/conf/httpd.conf / etc/httpd.conf [root@localhost conf] # vim / etc/httpd.conf / deflate search keyword search line LoadModule deflate_module modules/mod_deflate.so / / uncomment enable service / headers search keyword search line LoadModule headers_module modules/mod_headers.so / / uncomment start service / filter search keyword search line LoadModule filter_ Module modules/mod_filter.so / / uncomment and enable the service use / Listen to find the location of the keyword comment ipv6 Turn on ipv4 and change the listening port to the local address Listen 192.168.131.129:80#Listen 80 use the / ServerName search keyword And make the following changes: ServerName www.kgc.com:80 inserts the following in the last line of the file: AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript text/ipg text/png DeflateCompressionLevel 9 SetOutputFilter DEFLATE [root@localhost conf] # / usr/local/httpd/bin/apachectl-tSyntax OK// to verify whether the syntax is correct [root@localhost bin] # / apachectl start / / start the service [root@localhost bin] # netstat-ntap | grep 80tcp 0 0 192.168.35.131 systemctl stop firewalld.service * LISTEN 35887/httpd [root@localhost bin] # systemctl stop firewalld.service / / turn off the firewall [root@localhost bin] # setenforce 0 / / turn off the enhanced security function [root@localhost bin] # / apachectl-t-D DUMP_mooules | grep "expire" Syntax OK
Use the test machine win10 to test, enter the URL 192.168.131.129 in the browser to access the home page
Finally, open the fiddre software to grab the package.
Copy the pictures from the shared folder to the web page file directory and add the pictures to the web page
[root@localhost bin] # cd / abc/ [root@localhost LAMP] # lsapr-1.6.2.tar.gz fangdao.jpgapr-util-1.6.0.tar.gz httpd-2.4.29.tar.bz2awstats-7.6.tar.gz tupian.pngcronolog-1.6.2-14.el7.x86_64.rpm mysql-5.6.26.tar.gzDiscuz_X2.5_SC _ UTF8.zip php-5.6.11.tar.bz2 [root@localhost LAMP] # cp lf.jpg / usr/local/httpd/htdocs/ copy the image to the web folder [root@localhost LAMP] # cd / usr/local/httpd/ [root@localhost httpd] # cd htdocs/ [root@localhost htdocs] # lsindex.html tupian.png [root@localhost htdocs] # vim index.html It works!
Now when we visit the test machine again, we can see the added pictures. Through the package crawling software, we can see that the crawling information with pictures contains the gzip compression processing information at the port.
Configure caching time for web pages
■ configures Apache through the mod expire module so that the web page can be found on the client side.
The browser caches for a period of time to avoid duplicate requests
■ when the mod expire module is enabled, the header information of the page is automatically generated.
Expires tags and Cache-Control tags, thereby reducing customer
The frequency and number of visits on the side to reduce unnecessary traffic and increase visits
Ask the purpose of speed
■ modifies httpd.conf configuration file
● enables the mod expires module and sets documents in any format under the http protocol
Expires in seconds
ExpiresActive On
ExpiresDefault "access plus 60 seconds"
■ restarts the httpd service
Apache cache practice
After configuring the Apache web page compression, make the following configuration
Configure Apache Profil
[root@localhost htdocs] # vim / etc/httpd.conf inserts the following ExpiresActive On ExpiresDefault "access plus 50 seconds" at the end of the configuration file
Check syntax correctness and restart the service
[root@localhost htdocs] # pwd/usr/local/httpd/htdocs [root@localhost htdocs] # cd / usr/local/httpd/ [root@localhost httpd] # cd bin/ [root@localhost bin] #. / apachectl-t / / check the syntax Syntax OK [root@localhost bin] #. / apachectl stop [root@localhost bin] #. / apachectl start
We are using the browser in the test machine win10 to grab the package, and at this time we can see that the time we set for the web page cache appears in the header information.
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.