Centos7.4-apache Optimization Application III (Web optimization)

Source: Internet
Author: User

Apache Optimization App III (web optimization)
Directory
The first part of the preparatory work
Second part installs Apache service
Part three Apache Web page optimization-page compression
Part Four Apache web page optimizer-Web caching

The first part of the preparatory work
One: server: Linux system-centos 7.4;
IP Address: 192.168.80.10

Client: Take WIN7 as an example, test the result of verification, and the server in the same network segment;
IP Address: 192.168.80.2

Two: Prepare the package for compression

Apr-1.6.2.tar.gz and apr-util-1.6.0.tar.gz are required plugins for httpd2.4 later versions and must be installed

Third: Close the firewall with SELinux

Second part installs Apache service
One: Install the compilation tools and plugins
[[email protected] ~]# yum-y install \

GCC \
gcc-c++ \
Make \
Pcre-devel \
Expat-devel \
Perl

Two: Unzip:
[Email protected] ~]# Tar XF apr-1.6.2.tar.gz
[Email protected] ~]# Tar XF apr-util-1.6.0.tar.gz
[Email protected] ~]# Tar XF httpd-2.4.29.tar.bz2
[Email protected] ~]# MV apr-1.6.2 HTTPD-2.4.29/SRCLIB/APR
[Email protected] ~]# MV apr-util-1.6.0 httpd-2.4.29/srclib/apr-util

Three: Configuration (custom personalization)
[[Email protected] ~]# CD httpd-2.4.29//must enter the installation directory
[Email protected] httpd-2.4.29]#/configure \

--PREFIX=/USR/LOCAL/HTTPD \//Specifies to install the HTTPD program into the/USR/LOCAL/HTTPD directory
--ENABLE-SO \//Enable dynamic load module function
--enable-rewrite \//Enable Web page address rewriting for website optimization and Directory Migration
--enable-charset-lite \//enable character set support to support Web pages that are encoded using a variety of character sets
--ENABLE-CGI//Enable CGI scripting support for extended Web site application access

IV: Compilation and Installation
[[email protected] httpd-2.4.29]# make && make install

To add a httpd service to a system service
[Email protected] httpd-2.4.29]# CP/USR/LOCAL/HTTPD/BIN/APACHECTL/ETC/INIT.D/HTTPD
[Email protected] httpd-2.4.29]# VI/ETC/INIT.D/HTTPD
Add the following two lines (Note that "#" cannot be omitted):

Save exit

[[email protected] httpd-2.4.29]# chkconfig--add httpd//Add httpd to service Manager
[[email protected] httpd-2.4.29]# Systemctl daemon-reload//heavy-duty system System Manager

V: Edit httpd master configuration file
[Email protected] httpd-2.4.29]# vi/usr/local/httpd/conf/httpd.conf
Modify the following content:
ServerName localhost
Save exit
Optimized execution path (the original path of the executing program file is not in the PATH environment variable, do a soft link to make it executable)
[Email protected] httpd-2.4.29]# ln-s/usr/local/httpd/conf/httpd.conf/etc/
[Email protected] httpd-2.4.29]# ln-s/usr/local/httpd/bin/*/usr/local/bin/

Check for syntax errors
[Email protected] httpd-2.4.29]# httpd–t
Or: [[email protected] httpd-2.4.29]# apachectl–t

View Program version

Six: Start the service
[Email protected] httpd-2.4.29]# systemctl start httpd
[[email protected] httpd-2.4.29]# Systemctl enable httpd//set httpd to boot
[Email protected] httpd-2.4.29]# NETSTAT-ANPT | grep 80//View httpd service Run status

Seven: Validation
Accessing the server with the WIN7 client
Browser access: http://192.168.80.10

Validation successful
(Note that the default content of the Web page is:/usr/local/httpd/htdocs/index.html)

Part three Apache Web page optimization-page compression
One: Custom compression module
[Email protected] ~]# CD httpd-2.4.29
[Email protected] httpd-2.4.29]#/configure \

--PREFIX=/USR/LOCAL/HTTPD \
--ENABLE-SO \
--enable-rewrite \
--enable-charset-lite \
--ENABLE-CGI \
--enable-cgid \
--enable-deflate//Add compression module

[[email protected] httpd-2.4.29]# make && make install//compile installation

Two: Load the compression module
[[Email protected]t httpd-2.4.29]# vi/etc/httpd.conf//manual loading
Add a line of content:

Save exit

[[Email protected] httpd-2.4.29]# service httpd restart//restart Apache Services
[Email protected] httpd-2.4.29]# apachectl-d dump_modules | grep deflate//check to see if the compression module is loaded.

Three: Edit the configuration file
[Email protected] httpd-2.4.29]# vi/etc/httpd.conf
Add three lines of content:
Addoutputfilterbytype DEFLATE text/html text/plain text/css text/xml text/javascript image/png image/jpeg application/ x-httpd-php application/x-javascript//Start gzip compression for files of the above type
Deflatecompressionlevel 9//compression level
Setoutputfilter DEFLATE//enable the DEFLATE module to gzip compress the output of this site

[[email protected] httpd-2.4.29]# apachectl–t//Check syntax error

Four: Edit Default Web page display file
[Email protected] httpd-2.4.29]# cd/usr/local/httpd/htdocs/
[Email protected] htdocs]# VI index.html
Edit the following test page contents (if original content, delete all):
<title>--Compression test Page--</title>
<body>//Note picture path
</body>
Save exit


[[Email protected] htdocs]# service httpd restart//restart HTTP Services

V: Verify:
Win7 Access: 192.168.80.10

: Chinese characters are garbled
Resolve an unrecognized Chinese character problem
[Email protected] htdocs]# vi/etc/httpd.conf
Add the following content:
Adddefaultcharset Utf-8
Save exit
Re-access 192.168.80.10

Validation succeeds (if the webpage does not respond, clean up the cache)
Wireshark Capture Package Verification: active (read package after refresh page)

Successful compression

Part Four Apache web page optimizer-Web caching
[Email protected] ~]# apachectl-d dump_modules | grep expires//See if the Expires module (cache module) is loaded
[[Email protected] ~]# service httpd stop//stop HTTP Services

One: Configure the Cache module
[Email protected] ~]# CD httpd-2.4.29
[Email protected] httpd-2.4.29]#/configure \

--PREFIX=/USR/LOCAL/HTTPD \
--ENABLE-SO \
--enable-rewrite \
--enable-charset-lite \
--ENABLE-CGI \
--enable-cgid \
--enable-deflate \
--enable-expires//Add Cache module
[[email protected] httpd-2.4.29]# make && make install//compile installation

Two: Load the cache module
[[email protected] httpd-2.4.29]# vi/etc/httpd.conf//Load Cache module manually
Add the following content:
LoadModule Expires_module modules/mod_expires.so

Save exit
[[email protected] httpd-2.4.29]# apachectl–t//Check syntax error

Three: Edit the configuration file
[Email protected] httpd-2.4.29]# vi/etc/httpd.conf
Finally add the following content:
<ifmodule mod_expires.c>
Expiresactive on//Turn on cache function
ExpiresDefault "Access plus seconds"//cache time set 60 seconds (for files in any format (such as HTML,CSS,JS images, etc.) that expire after 60 seconds for HTTP protocol)
</IfModule>

Save exit
[Email protected] httpd-2.4.29]# apachectl-d dump_modules | grep expires//view module load

[[Email protected] httpd-2.4.29]# service httpd start//Turn on HTTP services

Four: Validation
Win7 under Wireshark Grab bag (Refresh page after read package)

Page cache is in effect

Centos7.4-apache Optimization Application III (Web optimization)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.