成都网站建设设计

将想法与焦点和您一起共享

构建虚拟Web主机实例

构建虚拟Web主机实例

虚拟web主机的定义:

●在同一台服务器中运行多个Web站点,其中每一个站点并不独立占用一台真正的计算机

成都创新互联-专业网站定制、快速模板网站建设、高性价比桃源网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式桃源网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖桃源地区。费用合理售后完善,十载实体公司更值得信赖。

虚拟主机的优势:

​ 虚拟Web主机指的是在同一台服务器中运行多个Web站点,其中的每一个站点实际上并不独自占用整个服务器,因此

被称为“虚拟Web主机”。 通过虚拟Web主机服务可以充分利用服务器的硬件资源,从而大大降低网站构建及运行成本。

httpd支持的虚拟主机类型:

●基于域名的虚拟主机 (应用最为广泛)
●基于IP地址的虚拟主机
●基于端口的虚拟主机

特征关系对应分别如下

  • ip相同、端口相同,域名不同;

  • ip不同,端口不同;

  • ip相同,端口不同。
1)基于域名构建示例

构建两个虚拟web站点

1.www.jj.com

2.www.kk.com

实际流程如下:

使用一台httpd服务器搭建,ip地址为192.168.68.145.具体构建过程如下:

1.为虚拟主机提供域名解析

安装bind和httpd服务:yum install -y bind httpd

[root@localhost ~]# vim /etc/named.conf 
[root@localhost ~]# head -21 /etc/named.conf |tail 
options {
        listen-on port 53 { any; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        recursing-file  "/var/named/data/named.recursing";
        secroots-file   "/var/named/data/named.secroots";
        allow-query     { any; };

[root@localhost ~]# vim /etc/named.rfc1912.zones 
[root@localhost ~]# vim /etc/named.rfc1912.zones 
[root@localhost ~]# head -34 /etc/named.rfc1912.zones | tail 
zone "ll.com" IN {
        type master;
        file "ll.com.zone";
        allow-update { none; };
};

zone "cc.com" IN {
        type master;
        file "cc.com.zone";
        allow-update { none; };
[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 ll.com.zone
[root@localhost named]# vim ll.com.zone 
[root@localhost named]# cp -p ll.com.zone cc.com.zone
[root@localhost named]# cat ll.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.68.145
[root@localhost named]# cat cc.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.68.145

[root@localhost named]# systemctl start named
[root@localhost named]# systemctl stop firewalld.service 
[root@localhost named]# setenforce 
usage:  setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@localhost named]# setenforce 0
[root@localhost named]# systemctl start httpd

测试是否成功

构建虚拟Web主机实例

[root@localhost named]# cd /etc/httpd/
[root@localhost httpd]# cd conf
[root@localhost conf]# ls
httpd.conf  magic
[root@localhost conf]# mkdir extra
[root@localhost conf]# ls
extra  httpd.conf  magic
[root@localhost conf]# cd extra/
[root@localhost extra]# vim vhost.conf 
[root@localhost extra]# cat vhost.conf 

  DocumentRoot "/var/www/html/ll/"
  ServerName www.ll.com
  ErrorLog "logs/www.ll.com.error_log"
  CustomLog "logs/www.ll.com.access_log" common
   
     Require all granted
  



  DocumentRoot "/var/www/html/cc/"
  ServerName www.cc.com
  ErrorLog "logs/www.cc.com.error_log"
  CustomLog "logs/www.cc.com.access_log" common
  
     Require all granted
  

[root@localhost extra]# vim /etc/httpd/conf/httpd.conf 
[root@localhost extra]# tail -2 /etc/httpd/conf/httpd.conf 
IncludeOptional conf.d/*.conf
Include conf/extra/vhost.conf

[root@localhost extra]# systemctl restart httpd

构建虚拟Web主机实例

2)基于端口构建示例

根据以上过程可以继续配置来完成基于端口的构建:

[root@localhost ~]# vim /etc/httpd/conf/extra/vhost.conf 
[root@localhost ~]# tail /etc/httpd/conf/extra/vhost.conf 


  DocumentRoot "/var/www/html/cc02/"
  ServerName www.cc.com
  ErrorLog "logs/www.cc02.com.error_log"
  CustomLog "logs/www.cc02.com.access_log" common
  
     Require all granted
  

[root@localhost ~]# cd /var/www/html/
[root@localhost html]# mkdir cc02
[root@localhost html]# ls
cc  cc02  ll
[root@localhost html]# cd cc02/
[root@localhost cc02]# vim index.html 
[root@localhost cc02]# cat index.html 

this is cc02 web

[root@localhost cc02]# vim /etc/httpd/conf/httpd.conf [root@localhost cc02]# head -43 /etc/httpd/conf/httpd.conf | tail -3 Listen 192.168.68.145:80 Listen 192.168.68.145:8080 #Listen 80 [root@localhost cc02]# systemctl restart httpd

测试验证:输入http://www.cc02.com:8080/即可

构建虚拟Web主机实例

3)基于IP地址构建示例
[root@localhost cc02]# vim  /etc/httpd/conf/extra/vhost.conf 
[root@localhost cc02]# cat /etc/httpd/conf/extra/vhost.conf 

  DocumentRoot "/var/www/html/ll/"
  #ServerName www.ll.com
  ErrorLog "logs/www.ll.com.error_log"
  CustomLog "logs/www.ll.com.access_log" common
   
     Require all granted
  



  DocumentRoot "/var/www/html/ll02/"
  #ServerName www.ll.com
  ErrorLog "logs/www.ll02.com.error_log"
  CustomLog "logs/www.ll02.com.access_log" common
   
     Require all granted
  

#
#  DocumentRoot "/var/www/html/cc/"
#  ServerName www.cc.com
#  ErrorLog "logs/www.cc.com.error_log"
#  CustomLog "logs/www.cc.com.access_log" common
#  
#     Require all granted
#  
#
#
#
#  DocumentRoot "/var/www/html/cc02/"
#  ServerName www.cc.com
#  ErrorLog "logs/www.cc02.com.error_log"
#  CustomLog "logs/www.cc02.com.access_log" common
#  
#     Require all granted
#  
#
[root@localhost cc02]# mkdir ll02
[root@localhost cc02]# cd ll02
[root@localhost ll02]# vim index.html
[root@localhost ll02]# cat index.html 

this is ll02 146

[root@localhost ll02]# vim /etc/httpd/conf/httpd.conf [root@localhost ll02]# head -43 /etc/httpd/conf/httpd.conf | tail -5 # prevent Apache from glomming onto all bound IP addresses. # Listen 192.168.68.145:80 Listen 192.168.68.146:80 #Listen 192.168.68.145:8080

测试验证:输入192.168.68.146

构建虚拟Web主机实例


新闻标题:构建虚拟Web主机实例
本文链接:http://chengdu.cdxwcx.cn/article/ghhjip.html