Directory
The first part of the preparatory work
Second part installs Apache service
The third part constructs the port-based virtual host
Part IV build a domain-based virtual host
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: Download the compressed package
http://httpd.apache.org/download.cgi//http Compression Pack
http://apr.apache.org/download.cgi//http Plug-in package
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
Put the plug-in into the httpd directory
[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 www.aa.com
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)
The third part constructs the port-based virtual host
One: Edit the HTTP master configuration file
[Email protected] ~]# vi/etc/httpd.conf
Include conf/conf.d/*.conf//new line to include child profiles
Save exit
Two: Create a virtual directory configuration file
[[email protected] ~]# cd/usr/local/httpd/conf///Enter HTTPD installation directory
[Email protected] conf]# mkdir CONF.D
[Email protected] conf]# CD CONF.D
[email protected] conf]# Touch vhost.conf
Three: Build a port-based virtual host (one address, multiple ports)
First step: Edit the configuration file
[Email protected] conf.d]# VI vhost.conf
Add the following content:
Listen 192.168.80.10:8080//Turn on monitor 8080 port (80 port is on by default, so do not turn on)
<virtualhost 192.168.80.10:80>//Virtual host 80 port access address
ServerAdmin [email protected]
documentroot/opt/aa///define home directory
ServerName www.aa.com//server name
Errorlog Logs/aa.com-error_log//Defining error log files
Customlog Logs/aa.com-access_log common//custom log file
</VirtualHost>
<directory "/OPT/AA" >
Options Indexes multiviews FollowSymLinks
AllowOverride None
Order Allow,deny
Allow from all
Require all granted
</Directory>
<virtualhost 192.168.80.10:8080>//Virtual host 8080 port access address
ServerAdmin [email protected]
documentroot/opt/bb///define home directory
ServerName www.bb.com//server name
Errorlog Logs/bb.com-error_log
Customlog Logs/bb.com-access_log Common
</VirtualHost>
<directory "/opt/bb" >
Options Indexes multiviews FollowSymLinks
AllowOverride None
Order Allow,deny
Allow from all
Require all granted
</Directory>
Save exit
Step two: Create a home directory of 80 ports and 8080 ports and create a default HTML file
[Email protected] ~]# mkdir/opt/aa/
[Email protected] ~]# cd/opt/aa/
[[email protected] aa]# echo
[Email protected] ~]# mkdir/opt/bb/
[Email protected] ~]# cd/opt/bb/
[[email protected] bb]# echo
Step three: Restart the httpd service
[Email protected] bb]# systemctl restart httpd
Fourth Step verification
Access http://192.168.80.10:80 under Win7
Access http://192.168.80.10:8080 under Win7
Validation successful
Four: Build a domain-based virtual host (one address, multiple domain names)
First step: Build a DNS server
[[email protected] ~]# yum install-y bind//Install DNS service
Edit the master configuration file
[Email protected] ~]# vi/etc/named.conf
Save exit
Editing a zone configuration file
[Email protected] ~]# Vi/etc/named.rfc1912.zones
Add the following content:
Save exit
Edit a zone data configuration file
[Email protected] ~]# cd/var/named/
[[email protected] named]# cp-p named.localhost aa.com.zone//Create aa.com data configuration file
[Email protected] named]# VI aa.com.zone
Edit the following content:
Save exit
[[email protected] named]# cp-p aa.com.zone bb.com.zone//Create bb.com data configuration file
(The IP address is the same as aa.com, the content is not modified)
[[email protected] named]# named-checkconf//Check syntax error (no error indicated correct)
[[email protected] named]# systemctl start named//Start DNS Service
[Email protected] named]# NETSTAT-ANPT | grep named//view DNS service health status
[email protected] named]# nslookup www.aa.com//parsing www.aa.com
[email protected] named]# nslookup www.bb.com//parsing www.bb.com
Parse success
[[email protected] named]# vi/etc/resolv.conf setting up Server DNS
Add the following content
ServerName 192.168.80.10
Save exit
Win7 the certificate
Set up DNS:
Test:
Verification successful, the DNS server is built here
Step Two: Edit the configuration file
[[email protected] named]# cd/usr/local/httpd/conf/conf.d/
[[email protected] conf.d]# vi vhost.conf
Edit the following (delete all the original content):
<virtualhost 192.168.80.10:80>
ServerAdmin [email Protected]
documentroot/opt/aa/
ServerName www.aa.com
errorlog logs/aa.com-error_log
Customlog logs/ Aa.com-access_log Common
</virtualhost>
<directory "/opt/aa";
Options Indexes multiviews FollowSymLinks
allowoverride None
Order allow,deny
allow from all
Require all granted
</directory
<virtualhost 192.168.80.10:80>
ServerAdmin [email protected]
documentroot/opt/bb/
ServerName www.bb.com
Errorlog Logs/bb.com-error_log
Customlog Logs/bb.com-access_log Common
</VirtualHost>
<directory "/opt/bb" >
Options Indexes multiviews FollowSymLinks
AllowOverride None
Order Allow,deny
Allow from all
Require all granted
</Directory>
Save exit
Step three: Create default HTML files for aa.com and bb.com
[Email protected] conf.d]# cd/opt/aa/
[[email protected] aa]# echo
[Email protected] aa]# cd/opt/bb/
[[email protected] bb]# echo
Fourth Step: Restart the service
[Email protected] bb]# systemctl restart httpd
Fifth Step: Verify
Access www.aa.com under Win7
Access www.bb.com under Win7
Validation successful
(Note that if the page does not display, clean up the browser's cache, history, if still not, then change a browser)
CentOS 7.4--apache Application II, building web hosting