基于IP的配置
首先在原本基础上增加两个IP地址
[root@localhost conf.d]# nmcli connection modify ens33 +ipv4.addresses 192.168.38.140
[root@localhost conf.d]# nmcli connection modify ens33 +ipv4.addresses 192.168.38.150
[root@localhost conf.d]# nmcli connection up ens33
然后配置虚拟主机
在/etc/nginx/conf.d/vhost.conf
server {
listen 192.168.38.135:80;
server_name localhost;
location / {
root /data/nginx1;
index index.html;
}
}
server {
listen 192.168.38.140:80;
server_name localhost;
location / {
root /data/nginx2;
index index.html;
}
}
server {
listen 192.168.38.150:80;
server_name localhost;
location / {
root /data/nginx3;
index index.html;
}
}
验证
基于端口的虚拟主机
直接配置