Apache之虚拟主机

什么是虚拟主机?

一台服务器部署多个站点。

分类

基于域名
基于端口
基于IP
实例:
www.heqiuyu.com /var/html/www
blog.heqiuyu.com /var/html/blog
bbs.heqiuyu.com /var/html/bbs
1.创建网站根目录:

[root@xiaoyu var]# tree /var/html/
/var/html/
├── bbs
├── blog
└── www

2.写入index.html内容

[root@xiaoyu html]# for name in www blog bbs;do echo "http://$name.heqiuyu.com" > /var/html/$name/index.html;done

3.编辑vhosts文件,并去掉http.conf注释

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

    ServerAdmin [email protected]
    DocumentRoot "/var/html/www"
    ServerName www.heqiuyu.com
    ServerAlias heqiuyu.com
    ErrorLog "logs/www_error_log"
    CustomLog "logs/www_access_log" common



    ServerAdmin [email protected]
    DocumentRoot "/var/html/blog"
    ServerName blog.heqiuyu.com
    ErrorLog "logs/blog_log"
    CustomLog "logs/blog_access" common



    ServerAdmin [email protected]
    DocumentRoot "/var/html/bbs"
    ServerName bbs.heqiuyu.com
    ErrorLog "logs/bbs_log"
    CustomLog "logs/bbs_access" common

4.在apachep配置文件内添加虚拟主机的目录权限


    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all


#
[root@xiaoyu ~]# /application/apache/bin/apachectl -t  检查语法
httpd: apr_sockaddr_info_get() failed for xiaoyu
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK
[root@xiaoyu ~]# /application/apache/bin/apachectl graceful 平滑重启

6.修改/etc/hosts文件,测试虚拟主机访问成功

host文件
10.10.9.201 www.heqiuyu.com
10.10.9.201 bbs.heqiuyu.com
10.10.9.201 blog.heqiuyu.com
测试虚拟主机
[root@xiaoyu ~]# lynx www.heqiuyu.com
[root@xiaoyu ~]# lynx bbs.heqiuyu.com
[root@xiaoyu ~]# lynx blog.heqiuyu.com

7.错误提示原因

[root@xiaoyu bin]# ./apachectl graceful
httpd: apr_sockaddr_info_get() failed for xiaoyu
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
解决方法:
修改http.conf   #ServerName www.example.com:80
成


你可能感兴趣的:(Apache之虚拟主机)