Centos 5.X 系统 Apache添加虚拟主机

编辑apache的配置文件,启用虚拟主机

vi /usr/local/apache/conf/httpd.conf

找到

Include conf/extra/httpd-vhosts.conf

把开头的#注释符号去掉,这样就打开了虚拟主机功能,保存退出

添加虚拟主机

vim /usr/local/apache/conf/extra/httpd-vhosts.conf

里面有两个example,大家其实根据example就可以添加自己的虚拟主机,但是这里为了增加文章篇幅,还是说明一下吧~~

以下是默认的虚拟主机例子

<VirtualHost *:80>

ServerAdmin webmaster@dummy-host.example.com

DocumentRoot "/usr/local/apache/docs/dummy-host.example.com"

ServerName dummy-host.example.com

ServerAlias www.dummy-host.example.com

ErrorLog "logs/dummy-host.example.com-error_log"

CustomLog "logs/dummy-host.example.com-access_log" common

</VirtualHost>

<VirtualHost *:80>

ServerAdmin webmaster@dummy-host2.example.com

DocumentRoot "/usr/local/apache/docs/dummy-host2.example.com"

ServerName dummy-host2.example.com

ErrorLog "logs/dummy-host2.example.com-error_log"

CustomLog "logs/dummy-host2.example.com-access_log" common

</VirtualHost>

创建属于自己的虚拟主机,以5abc.net举例

<VirtualHost *:80>

ServerAdmin webmaster@5abc.net

DocumentRoot "/usr/local/apache/htdocs/5abc"

ServerName 5abc.net

ServerAlias www.5abc.net

ErrorLog "logs/5abc.net-error_log"

CustomLog "logs/5abc.net-access_log" common

</VirtualHost>

把编辑好的虚拟主机配置,保存到httpd-vhosts.conf即可,别忘记删除两个example

DocumentRoot就是根目录的路径

创建目录,更改所属用户,用户组

由于目前在/usr/local/apache/htdocs/没有5abc这个目录,那么执行下面命令操作

mkdir /usr/local/apache/htdocs/5abc

chown -R www:www /usr/local/apache/htdocs/

Centos 5.X 系统 Apache添加虚拟主机:等您坐沙发呢!

发表评论

表情
还能输入210个字