区分不同的网站有三种方式:
1、ip区分
2、端口区分
3、域名区分
基于ip的虚拟主机配置
server {
listen 80;
server_name 192.168.11.181;
location / {
root html-181;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name 192.168.11.182;
location / {
root html-182;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
基于端口的虚拟主机
server {
listen 80;
server_name 192.168.11.182;
location / {
root html-182;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 81;
server_name 192.168.11.182;
location / {
root html-81;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
基于域名的虚拟主机
server {
listen 80;
server_name www.fuyi.com;
location / {
root html-181;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name m.fuyi.com;
location / {
root html-182;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}