apache下配置虚拟主机案例详解
Posted tianyik
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apache下配置虚拟主机案例详解相关的知识,希望对你有一定的参考价值。
案例说明:
域名:
www.tianyik.com /var/html/www
blog.tianyik.com /var/html/blog
bbs.tianyik.com /var/html/bbs
主机ip:192.168.31.36
创建站点目录:mkdir /var/html/{www,blog,bbs}
创建首页文件:
touch /var/html/{www,blog,bbs}/index.html 或者
for name in www blog bbs;do echo "http://$name.tainyik.com" >/var/html/$name/index.html;done
检查创建情况:for name in www blog bbs;do cat /var/html/$name/index.html;done
修改虚拟主机配置文件
vim httpd-vhost.conf 修改如下:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin tan.tianyik.com
DocumentRoot "/var/html/www"
ServerName www.tianyik.com
ServerAlias tianyik.com
ErrorLog "logs/dummy-host.example.com-error_log"
ErrorLog "logs/www-error_log"
CustomLog "logs/www-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin tan.tianyik.com
DocumentRoot "/var/html/blog"
ServerName blog.tianyik.com
ErrorLog "logs/blog-error_log"
CustomLog "logs/blog-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin tan.tianyik.com
DocumentRoot "/var/html/bbs"
ServerName bbs.tianyik.com
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
</VirtualHost>
注意:原来的<>需要删掉
修改主配置文件
去掉注释:Include conf/extra/httpd-vhosts.conf
找到下面一段(段中有#的注释行已删除)
<Directory "/application/apache2.2.31/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
修改为下面的一段:
<Directory "/var/html"> //不改会报403错误
Options FollowSymLinks //去掉Indexes,为安全
AllowOverride None
Order allow,deny
Allow from all
</Directory>
修改:ServerName localhost:80
不改可能会报错如下:
httpd: apr_sockaddr_info_get() failed for min
httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName
检查语法:/application/apache/bin/apachectl -t
平滑重启:/application/apache/bin/apachectl graceful
在本地做解析:修改hosts文件
添加:192.168.31.36 tianyik.com www.tianyik.com blog.tianyik.com bbs.tianyik.com
检查修改情况 ping
尝试访问:成功!
以上是关于apache下配置虚拟主机案例详解的主要内容,如果未能解决你的问题,请参考以下文章