一、基于IP配置
[root@localhost conf.d]# nmcli connection modify ens33 +ipv4.addresses 192.168.40.130
[root@localhost conf.d]# nmcli connection modify ens33 +ipv4.addresses 192.168.38.131
[root@localhost conf.d]# nmcli connection up ens33
配置虚拟主机
server {
listen 192.168.40.129:80;
server_name localhost;
location / {
root /data/nginx1;
index index.html;
}
}
server {
listen 192.168.40.130:80;
server_name localhost;
location / {
root /data/nginx2;
index index.html;
}
}
server {
listen 192.168.40.131:80;
server_name localhost;
location / {
root /data/nginx3;
index index.html;
}
}
二、基于端口的虚拟主机
server {
listen 80;
server_name localhost;
location / {
root /data/nginx1;
index index.html;
}
}
server {
listen 81;
server_name localhost;
location / {
root /data/nginx2;
index index.html;
}
}
server {
listen 82;
server_name localhost;
location / {
root /data/nginx3;
index index.html;
}
}
三、基于域名配置
server {
listen 192.168.40.129:80;
server_name www.nginx1.com;
location / {
root /data/nginx1;
index index.html;
}
}
server {
listen 192.168.40.130:80;
server_name www.nginx2.com;
location / {
root /data/nginx2;
index index.html;
}
}
server {
listen 192.168.40.131:80;
server_name www.nginx1.com;
location / {
root /data/nginx3;
index index.html;
}
}