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

Apache web page and security optimization-web page compression and caching (combination of theory and practice! )

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Overview of Apache page optimization 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 previous lower server configuration, and the previous configuration is no longer suitable for the current Internet era. In order to meet the needs of enterprises, we need to consider how to improve the performance and stability of Apache. This is the Apache optimization content optimization content configuration web page compression function working mode selection and parameter optimization configuration hotlink protection configuration hidden version number gzip introduction configuration Apache web page compression function is to use the gzip compression algorithm to compress the web page and then transfer it to the client browser reduces the number of bytes transmitted on the network, speeds up the loading speed of the web page and saves traffic Improve the user's browsing experience gzip has a better relationship with the crawling tools of the search engine Apache's compression module Apache implements web page compression functional modules include mod_gzip module mod_deflate module Apache 1.x there is no built-in web page compression technology, but you can use the third-party mod _ gzip module to perform compression Apache 2.x during development, the mod_deflate module was built in. Replace mod_gzipmod_gzip module and mod_deflate module compare * both use gzip compression algorithm, the operation principle is similar * mod_deflate compression speed is slightly faster, but mod_gzip compression ratio is slightly higher * mod_gzip takes up higher server CPU * servers with high traffic, using mod_deflate may load faster than mod_gzip to enable web page compression steps

Environment (web compression example) a Linux server (192.168.13.128) a win10 test machine 1, remote sharing and mounting to Linux 1) share the compression software package required by LAMP on Windows (if you have any questions here, please see the previous blog related article)

2) use remote sharing on Linux to obtain files and mount them to the / abc directory [root@localhost httpd] # mkdir / abc # # create a mount point / abcroot@lamp ~] # smbclient-L / / 192.168.100.3 / Sharename Type Comment LAMP-C7 Disk [root@lamp ~] # mount.cifs / / 192.168.100.3/LAMP-C7 / mnt # # remotely mount the package to / mnt directory 2 Compile and install Apache1 manually) extract the source code package to the / opt directory [root@lamp mnt] # cd / mnt # # switch to the / mnt directory [root@lamp mnt] # tar zxvf apr-1.6.2.tar.gz-C / opt/ # # extract the source code package to / opt. [root@lamp mnt] # tar zxvf apr-util-1.6.0.tar.gz-C / opt/.... [root@lampt mnt] # Tar jxvf httpd-2.4.29.tar.bz2-C / opt/... [root@lamp mnt] # cd / opt/ / enter the / opt directory [root@lamp opt] # ls / / View the unzipped file apr-1.6.2 apr-util-1.6.0 httpd-2.4.29 rh2) move the apr package to http And install the compilation tool [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 [root@localhost opt] # yum-y install\ gcc\ / / c language gcc-c++\ / / C++ language make\ / / compilation tool pcre-devel\ / / pcre language tool expat-devel\ / / identify tagged language tool perl\ pcre\ zlib-devel / / function library for data compression 3) configure the installation directory and each Module [root@lamp opt] # cd / opt/httpd-2.4.29/ [root@lamp httpd-2.4.29] #. / configure\ / configure-- prefix=/usr/local/httpd\-- enable-deflate\ / / configure compression module-- enable-expires\ / / configure cache module (required for the next cache experiment)-- enable-so\ / / apache core Open the heart module-- enable-rewrite\ / / enable the rewrite function Hotlink protection-enable-charset-lite\ / / supports character set Simplified Chinese-enable-cgi / / Universal Gateway Interface. 4) compile and install [root@lamp httpd-2.4.29] # make / / generate executable binaries... [root@lamp httpd-2.4.29] # make install / / copy binaries to the system Configure the application environment. 5) configure the http main 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/ # # switch to [root@localhost conf] # ln-s / usr/local/httpd/conf/httpd in the http main configuration file. Conf / etc/httpd.conf # # easy to manage and create soft connections # # overwrite the original startup script for easy operation And add it to the service manager [root@localhost conf] # cp / usr/local/httpd/bin/apachectl / etc/init.d/httpd / / copy the apache startup script to override the original httpd startup script [root@localhost conf] # vim / ETC init.dash httpdBinit.dhand httpdBinBing chkconfig: 35 852 steps description: Apache is a World Wide Web server / / downlink in #! / bin/sh Insert these two lines [root@localhost conf] # chkconfig-- add httpd / / add httpd to the SERVICE Manager [root@localhost conf] # vim / etc/httpd.conf # # configure the main configuration file Listen 192.168.13.128 add httpd 80 # set the listening address # Listen 80ServerName www.kgc.com:80 # # set the domain name LoadModule deflate_module modules/mod_deflate.so # # enable the compression module LoadModule headers_module modules / mod_headers.so # # enable header module # # add content from big G to the last line 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 [root@localhost conf] # service httpd start # # restart service [root] @ localhost conf] # systemctl stop firewalld.service [root@localhost conf] # setenforce 0 [root@localhost conf] # cd / usr/local/httpd/bin/ # # View the startup status of the deflate module [root@localhost bin]. / apachectl-t-D DUMP_MODULES | grep "deflate" deflate_module (shared) 6) switch to the site Edit the content of the web page [root@localhost conf] # cd. [root@localhost httpd] # pwd/usr/local/httpd [root@localhost httpd] # cd htdocs/ [root@localhost htdocs] # lsindex.html [root@localhost htdocs] # cat index.html It worksfetch 3, and install the fiddler package grab tool in win10

4, edit the page, add a picture 1) switch to your shared mount point Copy the picture to the site [root@localhost htdocs# cd / mnt # # switch to the mount point [root@localhost mnt] # cp kali.jpg / usr/local/httpd/htdocs/ # # copy the picture to the site [root@localhost mnt] # cd / usr/local/httpd/htdocs/ [root@localhost htdocs] # ls # # View the picture copied successfully index.html kali.jpg2) Edit the home page of the site [root@localhost ~] # Cd / usr/local/httpd/ [root@localhost httpd] # cd htdocs/ # # switch to site [root@localhost htdocs] # lsindex.html kali.jpg [root@localhost htdocs] # vim index.html # # to edit web content Add pictures to the page It works!

# # put the picture in the web page 5, test the web page and view the packet capture information

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

The environment compilation and installation is the same as the previous part, and the cache module is added to the configuration. The following is the configuration cache module operation 1, configure the main configuration file, open the cache module [root@localhost httpd-2.4.29] # vim / etc/http.confLoadModule expires_module modules/mod_expires.so # # open the cache module # # Big G last line add configuration file ExpiresActive On ExpiresDefault "access plus 50 seconds" 2, start Apachectl Turn off the firewall and restart the service [root@localhost httpd-2.4.29] # cd / usr/local/httpd/bin # # Test for syntax errors [root@localhost bin] #. / apachectl-t [root@localhost bin] #. / apachectl start # # turn on [root@localhost bin] # systemctl stop firewalld.service # # close the firewall [root@localhost bin] # setenforce 0 [root@localhost bin] #. / apachectl-t-D DUMP_MODULES | grep "expires" # # View module open status expires_module (shared) 3 Re-use the test machine to visit the web page and test the grab package

Thank you for reading!

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