Linux实现多IP访问多网站

1.前置条件:环境Linux9版本,Nginx
2.准备工作:关闭虚拟机防火墙及seLinux
setenforce 0
systemctl stop firewalld
安装Nginxsystemctl start nginx
3.给虚拟机添加多个IP
nmtui

重启服务
nmcli connection up ens160

4.进入/etc/nginx/conf.d下文件创建一个以".conf"结尾的文本文件,并写入配置
server { listen 192.168.87.110:80; root /test/110; location /{ index index.html; } } server { listen 192.168.87.120:80; root /test/120; location /{ index index.html; } } server { listen 192.168.87.130:80; root /test/130; location /{ index index.html; } }
5.创建目录并写入内容
mkdir /test/{110,120,130} -pv
echo this is 110/test/110/index.html
echo this is 120/test/120/index.html
echo this is 130/test/130/index.html
6.重启服务
systemctl restart nginx

posted @ 2024-10-21 19:58  hanasea  阅读(30)  评论(0)    收藏  举报