标签:-o dex rfc1912 虚拟web主机 com 自动 ice img 设定
虚拟Web主机在同一台服务器中运行多个Web站点,其中每一个站点并不独立
占用一台真正的计算机
1.基于域名的虚拟主机
2.基于IP地址的虚拟主机
3.基于端口的虚拟主机
1.安装DNS的软件包bind和httpd的服务,用以测试
[root@localhost ~]# yum install bind httpd -y
...
2.为虚拟主机提供域名解析
[root@localhost ~]# vim /etc/named.conf //进入主配置文件
options {
listen-on port 53 { any; }; //将原有的127.0.0.1替换成any
...
allow-query { any; }; //将localhost替换成any
[root@localhost ~]# vim /etc/named.rfc1912.zones //进入区域配置文件
zone "accp.com" IN { //第一个正向域名
type master;
file "accp.com.zone"; //指向区域数据配置文件accp.com.zone
allow-update { none; };
};
zone "kgc.com" IN { //第二个正向域名
type master;
file "kgc.com.zone"; //指向区域数据配置文件kgc.com.zone
allow-update { none; };
};
[root@localhost ~]# cd /var/named/ //进入/var/named/目录
[root@localhost named]# cp -p named.localhost accp.com.zone //复制模板文件named.localhost为accp.com.zone的区域数据配置文件
[root@localhost named]# vim accp.com.zone //编辑区域数据配置文件
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
www IN A 192.168.235.129 //添加解析A记录,并指向本主机IP地址
[root@localhost named]# cp -p accp.com.zone kgc.com.zone //复制accp.com.zone为kgc.com.zone的区域数据配置文件,无需进行修改
[root@localhost named]# systemctl start named //启动域名解析服务
[root@localhost named]# systemctl stop firewalld.service //关闭防火墙
[root@localhost named]# setenforce 0 //关闭增强型安全功能
1.修改客户机的DNS服务器地址为虚拟主机的地址
2.打开客户机的cmd命令提示符,使用nslookup命令加上域名即可获取解析到的地址
1.配置虚拟主机的配置文件
[root@localhost named]# cd /etc/httpd/conf //进入配置文件的conf目录
[root@localhost conf]# mkdir extra //创建扩展目录
[root@localhost conf]# cd extra/ //进入目录
[root@localhost extra]# vim vhost.conf //编辑虚拟主机配置文件,可自行定义
<VirtualHost *:80> //标签 *所有ip 80端口
DocumentRoot "/var/www/html/accp/" //站点目录
ServerName www.accp.com //站点域名
ErrorLog "logs/www. accp.com.error_log" //站点错误日志文件,logs为/var/log/httpd的软链接(相对路径)
CustomLog "logs/www.accp.com.access_1og" common //站点访问日志
<Directory "/var/www/html/"> //控制目录权限
Require all granted //允许所有访问
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/ www/ html/kgc/"
ServerName www. kgc. com
ErrorLog "logs/www.kgc.com.error_1og"
CustomLog "logs/www.kgc.com.access_log” common
<Directory "/var/www/html/">
Require all granted
</Directory>
</VirtualHost>
2.配置网页
[root@localhost extra]# cd /var/www/html/ //进入站点目录
[root@localhost html]# mkdir accp kgc
[root@localhost html]# cd accp/
[root@localhost accp]# vim index.html
<h1>this is accp web</h1>
[root@localhost accp]# cd ../kgc/
[root@localhost kgc]# vim index.html
<h1>this is kgc web</h1>
3.进入httpd.conf配置文件,声明包含先前创建的虚拟主机子配置文件
[root@localhost kgc]# cd /etc/httpd/conf
[root@localhost conf]# vim httpd.conf
...
Include conf/extra/vhost.conf //在末行接入此条目,用以声明包含虚拟主机子配置文件
[root@localhost extra]# systemctl start httpd //启动httpd服务
1.编辑虚拟主机配置文件
[root@localhost extra]# vim vhost.conf
... //省略之前设定好得部分配置
<VirtualHost *:8080> //添加accp域名的8080端口
DocumentRoot "/var/www/html/accp02"
ServerName www.accp.com
ErrorLog "logs/www.accp02.com.error_log"
CustomLog "logs/www.accp02.com.access_log" common
<Directory "/var/www/html/">
Require all granted
</Directory>
</VirtualHost>
2.创建新建的8080端口的网页站点
[root@localhost extra]# cd /var/www/html/
[root@localhost html]# mkdir accp02
[root@localhost html]# cd accp02/
[root@localhost accp02]# vim index.html
<h1>this is accp02 test web</h1>
3.修改httpd.conf配置文件的监听地址
vim /etc/httpd/conf/httpd.conf //进入配置文件
...
Listen 192.168.235.129:80
Listen 192.168.235.129:8080 //找到Listen条目并添加8080端口监听项
[root@localhost accp02]# systemctl restart httpd //重启服务
4.使用客户机网页
1.首先添加第二块网卡,然后他会自动获取到一个IP地址
2.配置虚拟主机的配置文件
[root@localhost accp02]# cd /etc/httpd/conf/extra/
[root@localhost extra]# ls
vhost.conf
[root@localhost extra]# vim vhost.conf
1 <VirtualHost 192.168.235.129:80>
2 DocumentRoot "/var/www/html/accp/"
3 ServerName www.accp.com
4 ErrorLog "logs/www.accp.com.error_log"
5 CustomLog "logs/www.accp.com.access_1og" common
6 <Directory "/var/www/html/">
7 Require all granted
8 </Directory>
9 </VirtualHost>
10
11 <VirtualHost 192.168.235.142:80>
12 DocumentRoot "/var/www/html/accp02"
13 ServerName www.accp.com
14 ErrorLog "logs/www.accp02.com.error_log"
15 CustomLog "logs/www.accp02.com.access_log" common
16 <Directory "/var/www/html/">
17 Require all granted
18 </Directory>
19 </VirtualHost>
3.修改httpd.conf配置文件的监听地址
[root@localhost extra]# vim /etc/httpd/conf/httpd.conf
...
Listen 192.168.235.129:80
Listen 192.168.235.142:80 //添加另一个IP的监听
[root@localhost extra]# systemctl restart httpd //重启服务
4.使用客户机网页
标签:-o dex rfc1912 虚拟web主机 com 自动 ice img 设定
原文地址:https://blog.51cto.com/14449521/2444901