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,访问网站

相关推荐
昌原的儿子LEO16 分钟前
进程和线程(2)
linux·服务器·网络
小王C语言30 分钟前
云服务器重置后,vscode无法远程连接
运维·服务器
Doep_key38 分钟前
Kubenetes控制器
运维·docker·容器
RoboWizard42 分钟前
金士顿高性能存储 赋能工控行业多场景深度落地
运维·服务器
会飞的土拨鼠呀1 小时前
Linux 真实内存使用率的核心计算标准
linux·运维·服务器
智购科技自动售货机工厂1 小时前
2026自动售货机语音支付模块集成:从声纹识别到支付闭环的工程实践~YH
大数据·服务器·网络·数据库·人工智能
小小谈电商2 小时前
2026 年 8 月|国内企业级商城源码服务商全方位测评报告
大数据·运维·小程序
hxhy002 小时前
异地组网实战:从 frp 中转到 Tailscale 直连,SSH 延迟 410ms → 29ms
运维·ssh
陈年老古董2 小时前
CentOS编译安装Python3.11完整教程
linux·笔记·学习·centos·python3.11
志栋智能2 小时前
从安全超自动化到超自动化安全的认知飞跃
运维·安全·自动化