什么是虛擬主機?
一臺服務器部署多個站點湿诊。
分類
基于域名
基于端口
基于IP
實例:
www.heqiuyu.com /var/html/www
blog.heqiuyu.com /var/html/blog
bbs.heqiuyu.com /var/html/bbs
1.創(chuàng)建網站根目錄:
[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
<VirtualHost *:80>
ServerAdmin heqiuyu@dummy-host.example.com
DocumentRoot "/var/html/www"
ServerName www.heqiuyu.com
ServerAlias heqiuyu.com
ErrorLog "logs/www_error_log"
CustomLog "logs/www_access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin heqiuyu@dummy-host.example.com
DocumentRoot "/var/html/blog"
ServerName blog.heqiuyu.com
ErrorLog "logs/blog_log"
CustomLog "logs/blog_access" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin heqiuyu@dummy-host.example.com
DocumentRoot "/var/html/bbs"
ServerName bbs.heqiuyu.com
ErrorLog "logs/bbs_log"
CustomLog "logs/bbs_access" common
</VirtualHost>
4.在apachep配置文件內添加虛擬主機的目錄權限
<Directory "/var/html" >
#
# 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
</Directory>
#
[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
成