一台linux中网站虚拟主机的完成主要有三种方式:a、根据ip地址;b、根据端口号;c、根据域名。一下为完成进程:(本试验的linux虚机系统为rhel5.6)
1、基于域名的实现:
这种方式需要搭建dns域名服务器。
#cat/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.22.133
NETWORK=192.168.22.0
NETMASK=255.255.255.0
BROADCAST=192.168.22.255
HWADDR=00:0C:29:89:05:2E
ONBOOT=yes
#cat/etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=httpd.com
#cat/etc/resolv.conf
nameserver192.168.22.133
searchhttpd.com
#yuminstallhttpd-y
#vim/etc/httpd/conf/httpd.conf
NameVirtualHost192.168.22.133:80 #将这一行注释符取消掉,*号改成ip地址
<80> #复制粘贴即可得到以下几行(nyyp)80>
ServerAdminwebmaster@dummy-host.example.com
DocumentRoot/www/bbs
ServerNamebbs.httpd.com
ErrorLoglogs/dummy-host.example.com-error_log
CustomLoglogs/dummy-host.example.com-access_logcommon
ServerAdminwebmaster@dummy-host.example.com
DocumentRoot/www/news
ServerNamenews.httpd.com
ErrorLoglogs/dummy-host.example.com-error_log
CustomLoglogs/dummy-host.example.com-access_logcommon
#mkdir-p/www/{news,bbs}
#vim/www/news/index.html
newspagehere
#vim/www/bbs/index.html
hello,thisisbbs
#servicenetworkrestart
#servicehttpdstart
#yuminstallbindbind-chrootbind-utilscaching-nameserver-y
#cd/var/named/chroot/etc
#cp-anamed.caching-nameserver.conf named.conf
#vimnamed.conf
options{
listen-onport53{any;};
directory “/var/named”;
dump-file “/var/named/data/cache_dump.db”;
statistics-file“/var/named/data/named_stats.txt”;
allow-query {any;};
allow-query-cache{any;};
};
zone“httpd.com”{
typemaster;
file“httpd.com.zone”;
};
zone“22.168.192.in-addr.arpa”{
typemaster;
file“22.168.192.zone”;
};
#cd../var/named
#touchhttpd.com.zone
#touch22.168.192.zone
#catlocalhost.zone>httpd.com.zone
#catnamed.local>22.168.192.zone
#vimhttpd.com.zone
$TTL 86400
@ INSOA @ root(
42 ;serial(d.adams)
3H ;refresh
15M ;retry
1W ;expiry
1D) ;minimum
INNS @
INA 192.168.22.133
bbs INA 192.168.22.133
news INA 192.168.22.133
#vim22.168.192.zone
$TTL 86400
@ IN SOA localhost.root.localhost. (
1997022700;Serial
28800 ;Refresh
14400 ;Retry
3600000 ;Expire
86400) ;Minimum
IN NS httpd.com.
133 IN PTR bbs.http.com.
133 IN PTR news.http.com.
#servicenamedstart
#hostbbs.httpd.com
bbs.httpd.comhasaddress192.168.22.133
#hostnews.httpd.com
news.httpd.comhasaddress192.168.22.133
#host192.168.22.133
133.22.168.192.in-addr.arpadomainnamepointernews.http.com.
133.22.168.192.in-addr.arpadomainnamepointerbbs.http.com.
在linux自带的火狐浏览器测试,如下图:
在另外一台虚拟的xp系统上面测试:(此时的linux和xp虚机均为桥接方式),如下图
ok,到此为止,linux下http域名虚拟主机的配置完美结束。
2、基于ip地址的实现
#cpifcfg-eth0ifcfg-eth0:1
#cpifcfg-eth0ifcfg-eth0:2
#catifcfg-eth0:1
DEVICE=eth0:1
BOOTPROTO=static
IPADDR=192.168.22.134
NETWORK=192.168.22.0
NETMASK=255.255.255.0
BROADCAST=192.168.22.255
HWADDR=00:0C:29:89:05:2E
ONBOOT=yes
#catifcfg-eth0:2
DEVICE=eth0:2
BOOTPROTO=static
IPADDR=192.168.22.135
NETWORK=192.168.22.0
NETMASK=255.255.255.0
BROADCAST=192.168.22.255
HWADDR=00:0C:29:89:05:2E
ONBOOT=yes
#servicenetworkrestart
#vim/etc/httpd/conf/httpd.conf
ServerAdminwebmaster@dummy-host.example.com
DocumentRoot/www/133
ServerName192.168.22.133
ErrorLoglogs/dummy-host.example.com-error_log
CustomLoglogs/dummy-host.example.com-access_logcommon
ServerAdminwebmaster@dummy-host.example.com
DocumentRoot/www/134
ServerName192.168.22.134
ErrorLoglogs/dummy-host.example.com-error_log
CustomLoglogs/dummy-host.example.com-access_logcommon
ServerAdminwebmaster@dummy-host.example.com
DocumentRoot/www/135
ServerName192.168.22.135
ErrorLoglogs/dummy-host.example.com-error_log
CustomLoglogs/dummy-host.example.com-access_logcommon
#要把NameVirtualHost关掉
#mkdir-p/www/{133,134,135}
#cat/www/133/index.html
hello,thisis133page.
#cat/www/134/index.html
hi,thisis134index
#cat/www/135/index.html
hey,thisis135indexpage
#servicehttpdrestart
到此,打开linux自带的火狐浏览器浏览,如下图所示:
基于ip地址的虚拟主机搭建成功。
3、基于端口的实现:
首先要手工配置一个ip地址,本实验使用的地址为192.168.22.133,改地址怎样配置见方式1详解。
#vim/etc/httpd/conf/httpd.conf
Listen80
Listen8080
Listen8081 #在Listen下面添加下面两行
。。。。
ServerAdminwebmaster@dummy-host.example.com
DocumentRoot/www/80
ServerName192.168.22.133
ErrorLoglogs/dummy-host.example.com-error_log
CustomLoglogs/dummy-host.example.com-access_logcommon
ServerAdminwebmaster@dummy-host.example.com
DocumentRoot/www/8080
ServerName192.168.22.133
ErrorLoglogs/dummy-host.example.com-error_log
CustomLoglogs/dummy-host.example.com-access_logcommon
ServerAdminwebmaster@dummy-host.example.com
DocumentRoot/www/8081
ServerName192.168.22.133
ErrorLoglogs/dummy-host.example.com-error_log
CustomLoglogs/dummy-host.example.com-access_logcommon
#mkdir-p/www/{80,8080,8081}
#cat/www/80/index.html
thisisport80page
#cat/www/8080/index.html
thisisport8080testpage
#cat/www/8081/index.html
hello,thisisport8081page
#servicehttpdrestart
到此用linux自带的火狐浏览器测试一下,如下图所示:
到此,根据端口方法的方式装备成功。
到此为止,linux网站虚拟主机的三种装备方法装备结束。
马哥教育-Linux学习-1群485374463
马哥教育-Linux学习-2群339184057