1. 基于ip的虚拟主机配置
假设Nginx服务同时配置了192.168.25.100/141两个IP
server {
listen 80;
server_name 192.168.25.141;
location / {
root /usr/share/nginx/html/html-141;
index index.html index.htm;
}
}
server {
listen 80;
server_name 192.168.25.100;
location / {
root /usr/share/nginx/html/html-100;
index index.html index.htm;
}
}
2. 基于端口的虚拟主机配置
server {
listen 81;
server_name 192.168.25.141;
location / {
root html-81;
index index.html index.htm;
}
server {
listen 82;
server_name 192.168.25.141;
location / {
root html-82;
index index.html index.htm;
}
3. 基于域名的虚拟主机配置
server {
listen 80;
server_name www.itma.com;
location / {
root html-www;
index index.html index.htm;
}
server {
listen 80;
server_name hehe.itma.com;
location / {
root html-hehe;
index index.html index.htm;
}