【实验】DNS+APACHE简单虚拟主机...

操作系统:CentOS 5.5
IP地址:192.168.137.200
实验域名:www.exp.com mail.exp.com game.exp.com
文中红色文字部分为需要配置的内容,蓝色部分为系统提示的内容
APACHE配置
需要安装的软件包:
httpd-manual-2.2.3-43.el5.centos
httpd-devel-2.2.3-43.el5.centos
httpd-2.2.3-43.el5.centos
1.检查软件包是否已经安装
[root@centos ~]# rpm -qa | grep httpd
2.修改配置文件
[root@centos ~]#vi /etc/httpd/conf/httpd.conf #在此我只列出了需要修改的地方,其他默认就可以
KeepAlive on #开启http1.1支持,网页上图片、CSS等文件较少的网站建议关闭(off)
ServerName www.exp.com #设置服务器名
DocumentRoot "/var/www/" #网站根目录
DirectoryIndex index.html #设置默认索引文件
AddDefaultCharset UTF-8 #字符编码,如:GBK、GB2312等
NameVirtualHost 192.168.137.200 #虚拟主机名称
<VirtualHost 192.168.137.200> #第一个虚拟主机
ServerAdmin [email protected]
DocumentRoot /var/www/html
ServerName www.exp.com
</VirtualHost>
<VirtualHost 192.168.137.200> #第二个虚拟主机
ServerAdmin [email protected]
DocumentRoot /var/www/mail
ServerName mail.exp.com
</VirtualHost>
<VirtualHost 192.168.137.200> #第三个虚拟主机
ServerAdmin [email protected]
DocumentRoot /var/www/game
ServerName game.exp.com
</VirtualHost>
3.创建/var/www/html和/var/www/mail和/var/www/game三个目录,分别在三个目录中创建index.html文件
由于/var/www/html目录默认已经存在,所以不需要再去创建
[root@centos ~]# mkdir /var/www/mail
[root@centos ~]# mkdir /var/wwwgame
[root@centos ~]# echo "This's master site" > /var/www/html/index.html //创建主站index.html文件
[root@centos ~]# echo "This's mail site" > /var/www/mail/index.html //创建mail站的index.html文件
[root@centos ~]# echo "This's game site" > /var/www/game/index.html //创建game站的index.html文件
4.启动APACHE
[root@centos ~]# service httpd restart
停止 httpd:[确定]
启动 httpd:[确定]
5.测试是否能够正常访访问,终端模式可以使用Lynx或links命令来浏览网页(前提是你已经安装这两个工具之一)
[root@centos ~]# lynx www.exp.com
[root@centos ~]# lynx mail.exp.com
[root@centos ~]# lynx game.exp.com
如果能看到三个不同内容的网页,说明配置成功
6.设置开机启动APACHE
[root@centos ~]# chkconfig httpd on
Tags: 

延伸阅读

最新评论

发表评论