本文是关于apache虚拟主机相关的配置,安装配置过程请参考http://ly36843.blog.51cto.com/3120113/1642118
一、配置www.a.com虚拟主机
编辑/usr/local/apache/conf/httpd.conf文件
[root@httpd ~]# vim /usr/local/apache/conf/httpd.conf Include conf/extra/httpd-vhosts.conf #打开这一样 编辑文件/usr/local/apache/conf/extra/httpd-vhosts.conf [root@httpd htdocs]# vim /usr/local/apache/conf/extra/httpd-vhosts.conf #添加虚拟主机的内容 <VirtualHost *:80> DocumentRoot "/data/www/a.com" ServerName www.a.com ErrorLog "logs/www.a.com-error_log" CustomLog "logs/www.a.com-access_log" common </VirtualHost> #创建站点目录和首页文件 [root@httpd ~]# mkdir -p /data/www/a.com [root@httpd ~]# echo "www.a.com" >> /data/www/a.com/index.html
检查httpd配置文件是否有误
[root@httpd ~]# /usr/local/apache/bin/apachectl -t Syntax OK
平滑重启httpd服务
[root@httpd ~]# /usr/local/apache/bin/apachectl graceful [root@httpd ~]# netstat -anpt|grep httpd tcp 0 0 :::80 :::* LISTEN 59398/httpd
在windows的hosts文件中添加www.a.com的域名解析记录,并验证结果
访问结果显示权限拒绝,这是因为在配置文件中没有对站点目录进行授权,解决办法如下
[root@httpd htdocs]# vim /usr/local/apache/conf/extra/httpd-vhosts.conf <VirtualHost *:80> DocumentRoot "/data/www/a-com/" ServerName www.a.com <Directory "/data/www/a-com"> Options FollowSymLinks #关闭索引 AllowOverride None Order allow,deny Allow from all Require all granted #在2.4版本以后对站点目录必须要打开Require all granted,否则访问站点会一直出现403错误 </Directory> ErrorLog "logs/www.a.com-error_log" CustomLog "logs/www.a.com-access_log" common </VirtualHost>
检查配置文件是否有错误
[root@httpd ~]# /usr/local/apache/bin/apachectl -t Syntax OK
平滑重启httpd服务
[root@httpd ~]# /usr/local/apache/bin/apachectl graceful [root@httpd ~]# netstat -anpt |grep httpd tcp 0 0 :::80 :::* LISTEN 59398/httpd
在windows下再次访问www.a.com
本文出自 “ly36843运维” 博客,请务必保留此出处http://ly36843.blog.51cto.com/3120113/1642155
原文地址:http://ly36843.blog.51cto.com/3120113/1642155