在以下是示例中,配置了三个虚拟主机,第一个虚拟主机表示所有对域名aaa.domain.com 的访问都由它来处理,第二个虚拟主机表示所有对域名 bbb.otherdomain.com的访问都由它来处理,第三个虚拟主机表示对域名 www.domain.com、domain.com,以及除了aaa.domain.com 之外的所有 *.domain.com二级域名的访问都由它来处理。每个虚拟主机的网页文件分别存放在不同的目录中,每个虚拟主机使用了不同的日志文件来记录访问日志。
---------------------------------------------------------------------------------------------------------------------http{ # 第一个虚拟主机 server { # 监听的端口 listen 80;
# 主机名称 server_nameaaa.domain.com;
# 访问日志文件存放路径 access_loglogs/aaa.domain.com.access.log combined;
location / { #默认首页文件,顺序从左到右,如果找不到index.html文件,则查找index.htm文件作为首页文件,以此类推 index index.html index.htm index.php;
#HTML网页文件的存放目录 root /data0/htdocs/aaa.domain.com; } }
# 第二个虚拟主机 server { # 监听的端口 listen 80;
# 主机名称 server_namebbb.otherdomain.com;
# 访问日志文件存放路径 access_loglogs/bbb.otherdomain.com.access.log combined;
location / { #默认首页文件,顺序从左到右,如果找不到index.html文件,则查找index.htm文件作为首页文件,以此类推 index index.html index.htm index.php;
#HTML网页文件的存放目录 root /data0/htdocs/bbb.otherdomain.com; } }
# 第三个虚拟主机 server { # 监听的端口 listen 80;
# 主机名称 server_namewww.domain.com domain.com *.domain.com;
# 访问日志文件存放路径 access_loglogs/bbb.domain.com.access.log combined;
location / { #默认首页文件,顺序从左到右,如果找不到index.html文件,则查找index.htm文件作为首页文件,以此类推 index index.html index.htm index.php;
#HTML网页文件的存放目录 root /data0/htdocs/domain.com; } }}