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 optimization-web page compression and caching

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

Share

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

Apache Web Optimization Overview In the enterprise, deploying Apache with only default configuration parameters can cause a lot of problems for the website, in other words, the default configuration is for the previous lower server configuration, and the previous configuration is no longer suitable for today's Internet era. In order to adapt to enterprise needs, you need to consider how to improve Apache performance and stability, this is Apache optimization content optimization content

Configure Web page compression

Selection of Working Mode and Optimization of Parameters

Configure anti-theft chain

Configure Hidden Version Number

...

Apache compression module

Apache implements web page compression function modules including

mod_gzip module

mod_deflate module

Apache 1.x

There is no built-in web page compression technology, but compression can be performed using a third-party mod_gzip module

Apache 2.x

At the time of development, mod_deflate was built in, replacing mod_gzip.

Steps to enable Web page compression

Example Demonstrate Deploying Web Compression Step 1: Sharing LAMP Toolkit Remotely on Linux [root@localhost ~]# smbclient -L //192.168.10.37 Sharename Type Comment --------- ---- ------- LAMP Disk [root@localhost ~]# mount.cifs //192.168.10.37/LAMP Step 2: Compile and install Apache

1. Extract source package

[root@localhost ~]# cd /mnt [root@localhost mnt ]# tar zvxf apr-1.6.2.tar.gz -C /opt[root@localhost mnt ]# tar zvxf apr-util-1.6.0.tar.gz -C /opt[root@localhost mnt ]# tar jxvf httpd-2.4.29.tar.bz2 -C /opt

2. Install compiler tools

[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 ]# yum -y install \gcc \gcc-c++ \make \pcre-devel \zlib-devel \expat-devel \pcre \perl

3. configure

[root@localhost opt ]# cd /opt/httpd-2.4.29/[root@localhost httpd-2.4.29 ]# ./ configure \--prefix=/usr/local/httpd \--enable-so \--enable-deflate \--enable-expires \--enable-rewrite \--enable-charset-lite \--enable-cgi

4. of compilation and installation

[root@localhost httpd-2.4.29 ]# make...... //omitting compilation [root@localhost httpd-2.4.29 ]# make install...... //Omit installation process

5. Open the relevant modules in the httpd main configuration file

[root@localhost httpd-2.4.29 ]# vim /usr/local/httpd/conf/httpd.conf 51 Listen 192.168.235.151:80 //Replace the listening address with this host 52 #Listen 80 on line 51//Comment on line 52 199 ServerName www.kgc.com:80//Set the domain name 106 LoadModule deflate_module modules/mod_deflate.so on line 199//Remove the comment #on line 106 to enable compression modules 113 LoadModule headers_module modules/mod_headers.so//Remove the comment #on line 113 to enable header modules//Add the following to the last line 510 511 AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml t ext/jpg text/javascript text/png512 DeflateCompressionLevel 9513 SetOutputFilter DEFLATE514 [root@localhost httpd-2.4.29 ]# systemctl stop firewalld.service [root@localhost httpd-2.4.29 ]# setenforce 0[root@localhost httpd-2.4.29 ]# cd /usr/local/httpd/bin[root@localhost bin]# ./ apachectl -t //check Syntax OK[root@localhost bin]# ./ apachectl start //Start Apache httpd (pid 71016) already running

6. Configure the site home page content

[root@localhost bin]# cd /usr/local/httpd/httdocs/[root@localhost httdocs]# vim index. html//edit the home page and put the picture [root@localhost httdocs]# cat index.html this is test web

[root@localhost htdocs]# lsgame.jpg index. htmlStep 3: Install fiddler package capture tool using Windows 7 client and view web pages

1. Double-click fiddler to install

2. Use your browser to enter the host IP of the service:192.168.235.151 to access the web page and see the image

3. Use the fiddler package capture tool to view

Configure cache time for web pages Apache is configured via mod_expire module to use web pages cached in client browsers for a period of time to avoid duplicate requests After mod_expire module is enabled, Expires tag and Cache-Control tag will be automatically generated in the page header information, thus reducing the frequency and number of client visits, reducing unnecessary traffic and increasing access speed. Enable Web caching function steps

Deploy Web caching functionality (based on previous actions)

Step 1: Open the relevant modules in the httpd main configuration file

[root@localhost htdocs]# vim /usr/local/httpd/conf/httpd.conf112 LoadModule expires_modules/mod_expires.so//Cancel the #comment on line 112 of the file and open the cache module//append ExpiresActive On ExpiresDefault "access plus 50 seconds" to the end of the file

Step 2: Check the file syntax and restart the service

[root@localhost htdocs]# cd /usr/local/httpd/bin[root@localhost bin]# ./ apachectl -tSyntax OK[root@localhost bin]# ./ apachectl stop //stop service [root@localhost bin]# ./ apachectl start //restart service httpd (pid 71016) already running [root@localhost bin]# systemctl stop firewalld.service [root@localhost bin]# setenforce 0

Step 3: Install fiddler package capture tool and view web pages using Windows 7 client

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: 214

*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