|
一、何为虚拟主机?
单个HTTPserver能提供多个http服务,根据访问的方式,可以分为以下几种虚拟主机:
1.端口虚拟主机
2.IP虚拟主机
3.域名虚拟主机
二、配置实现
1.端口虚拟主机
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| .......
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需要在服务器上)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| .......
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.域名虚拟主机
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| .......
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;
}
}
}
|
|
|
|
|
|
|
|