您现在的位置是:首页 > 其他

李清波 2014-06-01 其他 37392 复制当前网址

在服务器上apache配置多站点

以前用IIS的时候,可以在一台服务器上的80端口配置多个站点,通过修改主机头就可以很容易实现。

Apache要想实现类似的功能,其实也挺容易的,本篇文章以Windows环境下为例,Linux下的配置也大同小异。

打开httpd.conf配置文件,找到 

#Include conf/extra/httpd-vhosts.conf

去掉前面的#。然后打开\conf\extra\httpd-vhosts.conf

如果你的Apache端口像我一样,配置为80的话,

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@liqingbo.cn
    DocumentRoot "E:\www\test
    ServerName test.liqingbo.cn
</VirtualHost>
<VirtualHost *:90>
    ServerAdmin webmaster@liqingbo.cn
    DocumentRoot "E:\www\blog
    ServerName blog.liqingbo.cn
</VirtualHost>

这样,通过www.liqingbo.cn与blog.liqingbo.com访问就是两个项目了,

注意:在httpd.conf中配置的documentRoot,假如你配置为E:\www\myweb,则还需要在

NameVirtualHost *:80 这行代码下面,新增一个虚拟主机,

<VirtualHost *:80>
    ServerAdmin webmaster@liqingbo.cn
    DocumentRoot "E:\www\myweb"
    ServerName www.liqingbo.cn
</VirtualHost>

可能有的apache版本并没有ext目录,如果那样的话,则把<VirtualHost *:90>配置全部写在httpd.conf中即可。

但是访问的时候,可能会出现以下问题

apache出现You don't have permission to access / on this server. 提示

可以点击上面的链接查找影响的解决办法



文章来源:http://liqingbo.com/blog-243.html

评论