Linux上部署nginx实现多ip访问多网站

1,添加多个ip地址

使用nmtui命令或nmcli命令

nmtui方式:

nmcli方式:

root@localhost ip\]# nmcli conncetion ipv4.method manual ipv4.address 192.168.79.129/24 + 192.168.79.130/24 + 192.168.79.131 ipv4.gatway 192.68.79.2 ipv4.dns 114.114.114.114

激活网卡配置:

root@localhost ip\]# nmcli connection up ens160 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)

查看配置是否生效:

2,在/etc/nginx/conf.d/test_ip.conf 配置文件

server{

listen 192.168.79.129:80; -----监听IP地址,端口

root /ip/129;----访问目录文件

location / { ----访问本地/目录

index index.html;----索引文件名,默认 index.html

}

}

server{

listen 192.168.79.130:80;

root /ip/130;

location / {

index index.html;

}

}

server{

listen 192.168.79.131:80;

root /ip/131;

location / {

index index.html;

}

}

3,重启nginx服务

关闭相关服务

root@localhost \~\]# systemctl stop firewalld \[root@localhost \~\]# setenforce 0

重启配置

root@localhost /\]# systemctl restart nginx

4,创建相关目录文件

root@localhost /\]# mkdir /ip/{129,130,131} -pv mkdir: created directory '/ip' mkdir: created directory '/ip/129' mkdir: created directory '/ip/130' mkdir: created directory '/ip/131' \[root@localhost /\]# echo this is 129 \> /ip/129/index.html \[root@localhost /\]# echo this is 130 \> /ip/130/index.html \[root@localhost /\]# echo this is 131 \> /ip/131/index.html

5,访问网站

相关推荐
了一梨20 分钟前
[T113] 交叉编译 OpenCV 4.5.2 + face 模块
linux·笔记·opencv
我是谁??29 分钟前
在 Rocky Linux 9 无桌面环境中通过 SSH 安装 KVM 虚拟机(Rocky9含 XFCE 桌面/xubuntu20)完整指南
linux·服务器·ssh
3DVisionary36 分钟前
突破3C质检产能瓶颈:XTOM蓝光扫描仪配合自动化转台实现精密件批量检测
运维·人工智能·自动化·xtom扫描仪·自动化检测·消费电子质检·良率控制
困死,根本不会1 小时前
VMware Ubuntu 显示有线连接却无法上网|完整排查与解决笔记
linux·笔记·ubuntu
Luke Ewin1 小时前
Linux中部署Qwen3.5大模型
linux·运维·服务器·ai·llm·qwen3.5
xin_yao_xin1 小时前
Windows 下 Docker Desktop 安装教程及常用命令(2026 最新)
运维·docker·容器
春日见1 小时前
云服务器开发与SSH
运维·服务器·人工智能·windows·git·自动驾驶·ssh
minji...1 小时前
Linux 进程间通信(三)命名管道
linux·服务器·网络
还是做不到嘛\.2 小时前
DVWA靶场-Brute Force
运维·服务器·数据库·学习
克莱因3582 小时前
linux主机名与Hosts映射 (顺带个DNS简介
linux·运维·服务器