在linux下用Apache建虚拟主机(一个IP多个域名)

| No Comments | No TrackBacks

很多人都会在win2000下建立虚拟主机,在这里我就不多说了,下面介绍一下如何在linux下建立虚拟主机。
首先,在网上去下一个apache的源程序,可以http://www.apache.org/dist/httpd/binaries/linux/httpd-2.0.40-i686-pc-linux-gnu-rh73.tar.gz
得到。
下载后解决安装,进入解压后的目录后,执行./configure --prefix=/httpd  (*/httpd是你要安装在哪个目录,可以根据自己要求自己设定)

然后执行make
再执行make install
经过几分钟的等待后,apache就安装好了。
接下来,就是更改apache的配置。
cd /httpd/conf
vi httpd.conf
要更改的地方是:(比如我的IP是10.118.8.162)
ServerName 10.118.8.162
然后在文件里加入
NameVirtualHost 10.118.8.162
<VirtualHost 10.118.8.162>
ServerAdmin zxf@jk98.com
DocumentRoot /httpd/webserver/docs
ServerName 10.118.8.162
</VirtualHost>
#
<VirtualHost 10.118.8.162>
ServerAdmin zxf@jk98.com
DocumentRoot /httpd/webserver/www.test1.com
ServerName www.test1.com
</VirtualHost>
#
<VirtualHost 10.118.8.162>
ServerAdmin zxf@jk98.com
DocumentRoot /httpd/webserver/www.test2.com
ServerName www.test2.com
</VirtualHost>
其中:NameVirtualHost 10.118.8.162很重要,没有这个,虚拟主机是不可以建立成功的。在这里,我建立了两个域名为www.test1.com和www.test2.com的虚拟主机。
配置完成以后,存盘建出,然后,在/httpd下建立webserver的目录,进入目录后,再建立docs、www.test1.com、www.test2.com这三个目录。
docs目录是用来直接输入IP时所设置的页面目录,其他两个,是输入域名时所访问的目录。
接下来,就是在三个目录里,分别放入内容不同的index.html文件。
进入/httpd/bin启动apache。
好了,如果没有报错,就表明成功了一半。接下来,另外找一台计算机,在IE里输入www.test1.com和www.test2.com,如果显示的是两个不同的页面,就证明已经安装成功。
PS:什么?没有www.test1.com和www.test2.com这两个域名?呵呵,那你在你使用的计算机的C:\WINDOWS\system32\drivers\etc\hosts文件里加入
10.118.8.162 www.test1.com
10.118.8.162 www.test2.com
这两行。

No TrackBacks

TrackBack URL: http://www.wujianrong.com/mt-tb.cgi/2353

Leave a comment

About this Entry

This page contains a single entry by kevinwu published on April 23, 2007 7:16 PM.

linux 下apache 配置虚拟主机 was the previous entry in this blog.

Linux下apache,tomcat配置 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.