一、何为虚拟主机?
单个HTTPserver能提供多个http服务,根据访问的方式,可以分为以下几种虚拟主机:
1.端口虚拟主机
2.IP虚拟主机
3.域名虚拟主机
二、配置实现
1.端口虚拟主机
.......
http {
....
server {
listen 8080; # 这里设置虚拟主机的监听端口
server_name virtual_host1;
location / {
root /var/vhost/vhost1; #vhost1的首页位置
index index.html index.htm;
}
}
server {
listen 80; #这里设计虚拟主机的监听端口
server_name virtual_host2;
location / {
root /var/vhost/vhost2; #vhost2的首页位置
index index.html index.htm;
}
}
}2.IP虚拟主机(IP1,IP2需要在服务器上)
.......
http {
....
server {
listen IP1:80; # 这里设置虚拟主机的监听端口
server_name virtual_host1;
location / {
root /var/vhost/vhost1; #vhost1的首页位置
index index.html index.htm;
}
}
server {
listen IP2:80; #这里设计虚拟主机的监听端口
server_name virtual_host2;
location / {
root /var/vhost/vhost2; #vhost2的首页位置
index index.html index.htm;
}
}
}3.域名虚拟主机
.......
http {
....
server {
listen IP1:80;
server_name #虚拟域名
location / {
root /var/vhost/vhost1; #vhost1的首页位置
index index.html index.htm;
}
}
server {
listen IP2:80;
server_name #虚拟域名
location / {
root /var/vhost/vhost2; #vhost2的首页位置
index index.html index.htm;
}
}
}本文出自 “Lu2Yu” 博客,请务必保留此出处http://lu2yu.blog.51cto.com/10009517/1626497
原文:http://lu2yu.blog.51cto.com/10009517/1626497