Building a virtual web host

Source: Internet
Author: User

虚拟Web主机指的是在同一台服务器中运行多个Web站点,其中的每一个站点实际上并不独自占用整个服务器,因此被称为“虚拟Web主机”。 通过虚拟Web主机服务可以充分利用服务器的硬件资源,从而大大降低网站构建及运行成本 使用httpd可以非常方便地构建虚拟主机服务器,只需要运行一个httpd服务就能够同时支撑 大量的Web站点。Httpd支持的虚拟主机类型包括以下三种:基于域名的虚拟主机 : 不同的域名 相同的IP基于端口的虚拟主机 : 不使用域名、IP来区分不同站点的内容,而是用不同的TCP端口号.基于IP地址的虚拟主机 : 不同的域名 不同的IP ( 需要加网络接口 ,应用的不广泛)由于基于IP地址的虚拟主机需要添加网络接口 使用不广泛,所以下面只对基于域名的虚拟主机 和基于端口的虚拟主机 进行介绍。

.

 1: Domain-based virtual host # VIM/ETC/HTTPD/CONF/HTTPD.CONF//Configuration httpd.conf ServerName linux.zkc.com:80 Listen 192.168. 100.101:80//Listening IP port #Listen 80//Comment this line creates a separate configuration folder # Vim/etc/httpd/conf.d/vho st.conf//Create vhost.conf namevirtualhost 192.168.100.101:80 <virtualhost 192.168.100.101:80> ServerAdmin [email protected]//Establish an Administrator mailbox documentroot/opt/benet/// Site Directory ServerName www.benet.com//domain www.benet.com errorlog logs/benet.com -error_log//error log Customlog Logs/benet.com-access_log common//access log < /virtualhost><virtualhost 192.168.100.101:80> ServerAdmin [email protected] Documentroot/opt/acc P/servername www.accp.com errorlog logs/accp.com-error_log customlog logs/accp.com-access_log common</Virt Ualhost> 


.

为虚拟机准备网页文档mkdir /opt/benet     mkdir /opt/accpecho "this is benet" > /opt/benet/index.html    echo "this is accp" > /opt/accp/index.html

.

域名解析需要安装配置DNSrpm -ivh /mnt/Packages/bind-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm vim /etc/named.conf     //DNS修改主配置文件   listen-on port 53 { 192.168.100.101; };   allow-query     { any; };

 # vim /etc/named.rfc1912.zones  //修改DNS区域文件  zone "benet.com" IN {    type master;    file "benet.com.zone";    allow-update { none; };};    zone "accp.com" IN {        type master;        file "accp.com.zone";        allow-update { none; };};

修改DNS区域数据文件# cd /var/named/# cp -p named.localhost benet.com.zone  # vim benet.com.zone @  IN SOA  @ admin. (                0   ; serial                1D  ; refresh                1H  ; retry                1W  ; expire                3H )    ; minimumNS  @A   127.0.0.1www IN A    192.168.100.101

# cp -p benet.com.zone accp.com.zone# service named restart# service httpd restart打开IE浏览器 输入 www.benet.com   www.accp.com

2:基于端口的虚拟主机   (这里测试的是8080端口)# vim /etc/httpd/conf.d/vhost.conf..........        //添加下面几行NameVirtualHost 192.168.100.101:8080<VirtualHost 192.168.100.101:8080>     ServerAdmin [email protected]     DocumentRoot /opt/benet01/     ServerName www.benet.com     ErrorLog logs/benet.com-error_log     CustomLog logs/benet.com-access_log common</VirtualHost>

为www.benet.com:8080    准备一个测试网页# mkdir /opt/benet01# echo "this is benet8080" > /opt/benet01/index.html# vi /etc/httpd/conf/httpd.conf    Listen 192.168.100.101:8080

 在IE浏览器里 输入www.benet.com:8080

Building a virtual web host

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.