Construction of Web Hosting
1, the virtual host Introduction
Enterprises commonly used web hosting divided into three kinds:
(1) based on the domain name
(2) based on the port
-based (3) IP
Virtual web host
Run multiple web sites on the same physical server, each site does not occupy a separate real computer
httpd supported virtual host type
(1) based virtual hosting
(2) IP address-based virtual hosts
(3) based on the virtual master port
Apache connections remain
Apache holding connection parameters
(1) KeepAlive
whether the connection remains open, OFF closed, ON opening
(2) KeepAlive Timeout
a maximum connection time between the request multiple coarse, over which time two requests disconnection
(3) MaxKeepAliveRequests
a maximum transmission connection can the number of requests
Apache access control
(1) action
to control access to the site resources
to add access permissions for specific websites directory
(2) commonly used in access control
address of the client limit
user limit
Client-based access control address
Require the use of access control configuration items, according to the order restrictions
Useful in <Location>, <Directory>, <Files>, <Limit> configuration section
Require common syntax of configuration items
Require all granted
Require all denied
Require local
Require [not ] host <主机名或域名列表>
Require [not ] ip <IP地址或网段列表>
To placed <RequireAll> not block access to the use of </ RequireAll> vessel and specify the corresponding restriction policy in the vessel
Require command modes
2, build a virtual host - based domain name
2.1 Configuration Environment
DNS installation and service httpd
[root@localhost ~]# yum install bind httpd -y
Modify the DNS master configuration file
[root@localhost ~]# vim /etc/named.conf
Configuring DNS zone configuration file
[root@localhost ~]# vim /etc/named.rfc1912.zones
#在区域配置文件中添加下列内容
zone "kgc.com" IN {
type master;
file "kgc.com.zone";
allow-update { none; };
};
zone "accp.com" IN {
type master;
file "accp.com.zone";
allow-update { none; };
};
Configuring DNS zone data configuration file
[root@localhost ~]# cd /var/named/
[root@localhost named]# ls //查看
data dynamic named.ca named.empty named.localhost named.loopback slaves
[root@localhost named]# cp -p named.localhost kgc.com.zone
[root@localhost named]# vim kgc.com.zon
The kgc regional data configuration file, copy to copy without modification under accp
[root@localhost named]# cp -p kgc.com.zone accp.com.zone
Open DNS service, turn off the firewall and security features
[root@localhost named]# systemctl start named
[root@localhost named]# systemctl stop firewalld.service
[root@localhost named]# setenforce 0
2.2 Configuring static tests done on windows10 DNS to resolve the address
Open cmd whether the test can be resolved to the domain name on windows10
2.3 virtual host configuration
[root@localhost named]# cd /etc/httpd/
[root@localhost httpd]# ls
conf conf.d conf.modules.d logs modules run
[root@localhost httpd]# cd conf/
[root@localhost conf]# ls
httpd.conf magic
[root@localhost conf]# mkdir extra
[root@localhost conf]# cd extra/
[root@localhost extra]# vim vhost.conf //创建扩展文件
<VirtualHost *:80> //标题,固定格式
DocumentRoot "/var/www/html/kgc" //站点
ServerName www.kgc.com //域名
ErrorLog "logs/www.kgc.com.error_log" //错误日志文件
CustomLog "logs/www.kgc.com.access_log" common //访问日志文件
<Directory "/var/www/html/">
Require all granted //访问权限
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/html/accp"
ServerName www.accp.com
ErrorLog "logs/www.accp.com.error_log"
CustomLog "logs/www.accp.com.access_log" common
<Directory "/var/www/html/">
Require all granted
</Directory>
</VirtualHost>
Configuration Page Show Contents
[root@localhost httpd]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# mkdir kgc accp
[root@localhost html]# ls
accp kgc
[root@localhost html]# cd kgc/
[root@localhost kgc]# vim index.html
<h1>this is kgc web</h1>
[root@localhost kgc]# cd ../accp/
[root@localhost accp]# vim index.html
<h1>this is accp web</h1>
Absolute path configuration page
[root@localhost accp]# cd /etc/httpd/
[root@localhost httpd]# ls
conf conf.d conf.modules.d logs modules run
[root@localhost httpd]# cd conf/
[root@localhost conf]# vim httpd.conf
Include conf/extra/vhost.conf
Services start http
[root@localhost conf]# systemctl start httpd
2.4 test their pages on windows10
3, build a virtual host - based port
3.1 modify the domain name based on the basis of
进入扩展文件,配置,添加一个端口
[root@localhost conf]# cd extra/
[root@localhost extra]# vim vhost.conf
<VirtualHost *:8080>
22 DocumentRoot "/var/www/html/accp02"
23 ServerName www.accp.com
24 ErrorLog "logs/www.accp02.com.error_log"
25 CustomLog "logs/www.accp02.com.access_log" common
26 <Directory "/var/www/html/">
27 Require all granted
28 </Directory>
29 </VirtualHost>
[root@localhost extra]# cd /var/www/html/ //创建accp02 zhandian
[root@localhost html]# ls
accp kgc
[root@localhost html]# mkdir accp02
[root@localhost html]# cd accp02/
[root@localhost accp02]# vim index.html
<h1>this is accp02 web</h1>
Enter an absolute path, modify
[root@localhost accp02]# vim /etc/httpd/conf/httpd.conf
Restart Web Services
[root@localhost accp02]# systemctl restart httpd
View port
[root@localhost accp02]# netstat -ntap
3.2 windows10 enter test
4, building a virtual host - IP-based
4.1 Configuration Environment
IP-based to a different IP address, we first add a network adapter on the virtual machine, and then let him get IP address automatically.
Second card been added, an IP address of 192.168.45.128 he
enters vhost.conf modified group IP configuration settings
[root@localhost accp02]# cd /etc/httpd/conf/extra/
[root@localhost extra]# vim vhost.conf
1 <VirtualHost 192.168.45.135:80>
2 DocumentRoot "/var/www/html/kgc"
3 ErrorLog "logs/www.kgc.com.error_log"
4 CustomLog "logs/www.kgc.com.access_log" common
5 <Directory "/var/www/html/">
6 Require all granted
7 </Directory>
8 </VirtualHost>
9
10 <VirtualHost 192.168.45.128:80>
11 DocumentRoot "/var/www/html/kgc02"
12 ErrorLog "logs/www.kgc02.com.error_log"
13 CustomLog "logs/www.kgc02.com.access_log" common
14 <Directory "/var/www/html/">
15 Require all granted
16 </Directory>
17 </VirtualHost>
Create a page file, and add pages to display content
[root@localhost extra]# cd /var/www/html/
[root@localhost html]# mkdir kgc02
[root@localhost html]# cd kgc02/
[root@localhost kgc02]# vim index.html
<h1>this is kgc02 web</h1>
Enter http profile
[root@localhost kgc02]# vim /etc/httpd/conf/httpd.conf
Restart Web Services
[root@localhost kgc02]# systemctl restart httpd