Environment configuration:
Configure DNS for Domain name resolution
- Install the bind package.
Yum install-y bind
2. Modify the bind configuration file.
Vim/etc/named.conf
Listen-on Port 53 {192.168.200.101;};
allow-query {any;};
Vim/etc/named.rfc1912.zones
Zone "A.com" in {
Type master;
File "A.com.localhost";
allow-update {none;};
};
3. Modify the bind zone file.
cd/var/named/
Cp-p Named.localhost A.com.loaclhost
Vim A.com.loaclhost
$TTL 1D
@ in SOA a.com. Rname.invalid. (
0; Serial
1D; Refresh
1H; Retry
1W; Expire
3H); Minimum
NS dns.a.com.
DNS A 192.168.200.101
www A 192.168.200.102
M A 192.168.200.102
4. Bind server syntax Check to start the BIND service.
Named-checkconf/etc/named.conf
Named-checkconf/etc/named.rfc1912.zones
Named-checkzone A.com/var/named/a.com.localhost
Systemctl Start named
Systemctl Enable named
The Web server installs the Apache package.
Yum install-y httpd Httpd-devel
Virtual directory
- Virtual directory configuration.
Vim/etc/httpd/conf/httpd.conf
ServerName www.a.com:80
Vim/etc/httpd/conf.d/vhost.conf
Alias/vshare "/var/www/share"
<directory "/var/www/share" >
allowoverride None
Options IncludesNOEXEC
Order Allow,deny
Allow from all
</directory>
2. Create a site directory, configure the default document
Mkdir/var/www/share/
echo "Share" >/var/www/share/index.html
Chown apache:apache/var/www/share/
3. Apache syntax detection, start Apache service
Httpd-t
Systemctl Start httpd
4. Client DNS is set to 192.168.200.101 and then Access Www.a.com/vshare
User authentication
- Virtual directory configuration.
Vim/etc/httpd/conf.d/vhost.conf
Alias/vhome "/var/www/home"
<directory "/var/www/home" >
AuthType Basic
AuthName "Enter user and password"
Authuserfile/etc/httpd/users-password
Require Valid-user
Options IncludesNOEXEC
allowoverride None
Order Allow,deny
Allow from all
</directory>
2. Create a site directory, configure the default document
mkdir/var/www/home/
echo "Home" >/var/www/home/index.html
Chown Apache:apache/var/www/home
3. Create user authentication
Htpasswd-c/etc/httpd/users-password user123
Htpasswd/etc/httpd/users-password user456 #第二次创建不加-C
4. Apache syntax detection, start Apache service
Httpd-t
Systemctl Restart httpd
5. Client DNS is set to 192.168.200.101 and then Access Www.a.com/vhome
Port-based virtual host
- Virtual directory configuration.
Vim/etc/httpd/conf/httpd.conf
ServerName www.a.com:80
80 Listen
Listen 8888
Listen 9999
Vim/etc/httpd/conf.d/vhost.conf
<virtualhost www.a.com:8888>
ServerName www.a.com:8888
serveradmin [email protected]
documentroot/var/www/port8888
Errorlog Logs/port8888/error.log
Customlog Logs/port8888/access.log combined
</virtualhost>
<virtualhost www.a.com:9999>
ServerName www.a.com:9999
serveradmin [email protected]
documentroot/var/www/port9999
Errorlog Logs/port9999/error.log
Customlog Logs/port9999/access.log combined
</virtualhost>
mkdir/var/www/port8888
mkdir/var/www/port9999
mkdir/etc/httpd/logs/port8888
mkdir/etc/httpd/logs/port9999
Chown-r apache:apache/var/www/port*
Chown-r apache:apache/etc/httpd/logs/port*
echo "port8888" >/var/www/port8888/index.html
echo "port9999" >/var/www/port9999/index.html
3. Apache syntax detection, start Apache service
Httpd-t
Systemctl Restart httpd
IP-based virtual host
Configure a multiple IP address for testing
Ifconfig ens32:0 192.168.200.202/24
IP addr
2:ENS32: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
inet 192.168.200.102/24 BRD 192.168.200.255 Scope Global ENS32
inet 192.168.200.202/24 BRD 192.168.200.255 scope Global Secondary ens32:0
Vim/etc/httpd/conf.d/vhost.conf
<virtualhost 192.168.200.102:80>
ServerName 192.168.200.102:80
serveradmin [email protected]
documentroot/var/www/102
Errorlog Logs/102/error.log
Customlog Logs/102/access.log combined
</virtualhost>
<virtualhost 192.168.200.202:80>
ServerName 192.168.200.202:80
serveradmin [email protected]
documentroot/var/www/202
Errorlog Logs/202/error.log
Customlog Logs/202/access.log combined
</virtualhost>
mkdir/var/www/102
mkdir/var/www/202
mkdir/etc/httpd/logs/102
mkdir/etc/httpd/logs/202
Chown-r apache:apache/var/www/*02
Chown-r apache:apache/etc/httpd/logs/*02
echo "102" >/var/www/102/index.html
echo "202" >/var/www/202/index.html
Apache syntax detection, start Apache service
Httpd-t
Systemctl Restart httpd
Domain-based virtual host
- Virtual directory configuration.
Vim/etc/httpd/conf/httpd.conf
ServerName a.com:80
Vim/etc/httpd/conf.d/vhost.conf
<virtualhost www.a.com:80>
ServerName www.a.com:80
serveradmin [email protected]
Documentroot/var/www/www
Errorlog Logs/www/error.log
Customlog Logs/www/access.log combined
</virtualhost>
<virtualhost m.a.com:80>
ServerName m.a.com:80
serveradmin [email protected]
documentroot/var/www/m
Errorlog Logs/m/error.log
Customlog Logs/m/access.log combined
</virtualhost>
Mkdir/var/www/www
mkdir/var/www/m
Mkdir/etc/httpd/logs/www
mkdir/etc/httpd/logs/m
Chown-r apache:apache/var/www/www
Chown-r apache:apache/var/www/m
Chown-r apache:apache/etc/httpd/logs/www
Chown-r apache:apache/etc/httpd/logs/m
echo "www" >/var/www/www/index.html
echo "M" >/var/www/m/index.html
Apache syntax detection, start Apache service
Httpd-t
Systemctl Restart httpd
SSL-based Web site configuration.
Yum install-y mod_ssl OpenSSL openssl-devel
Cd/etc/pki/tls/private
OpenSSL genrsa 1024x768 > Www.a.com.key
Cd.. /certs/
OpenSSL req-new-x509-days 365-key./private/www.a.com.key-out www.a.com.crt
Country Name (2 letter code) [GB]: Enter the country region code, such as CN in China
State or province name (full name) [Berkshire]: Region Province
Locality name (eg, city) [Newbury]: Town Name
Organization name (eg, company) [My Companies Ltd]: corporate name
Organizational unit name (eg, section) []: Department Name
Common name (eg, your name or your server ' s hostname) []: Requesting a certificate domain name
email address []: e-mail
Vim/etc/httpd/conf.d/ssl.conf
DocumentRoot "/var/www/ssl"
ServerName www.a.com:443
Sslcertificatefile/etc/pki/tls/certs/www.a.com.crt
107 Sslcertificatekeyfile/etc/pki/tls/private/www.a.com.key
Mkdir/var/www/ssl
Chown-r apache:apache/var/www/ssl/
echo "1 2 3 4 5" >/var/www/ssl/index.html
Apache syntax detection, start Apache service
Httpd-t
Systemctl Restart httpd
Apache virtual directory, user authentication, port/ip/domain-based virtual host, SSL