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

相关推荐
知星小度S7 分钟前
系统核心解析:深入文件系统底层机制——Ext系列探秘:从磁盘结构到挂载链接的全链路解析
linux
2401_8904430212 分钟前
Linux 基础IO
linux·c语言
字节数据平台1 小时前
刚刚,火山引擎多模态数据湖解决方案发布大数据运维Agent
大数据·运维·火山引擎
智慧地球(AI·Earth)1 小时前
在Linux上使用Claude Code 并使用本地VS Code SSH远程访问的完整指南
linux·ssh·ai编程
原神启动11 小时前
Docker 场景化作业:生产环境容器操作实训
运维·docker·容器
云老大TG:@yunlaoda3602 小时前
如何通过华为云国际站代理商CSBS进行备份策略设置?
运维·数据库·华为云
老王熬夜敲代码2 小时前
解决IP不够用的问题
linux·网络·笔记
zly35002 小时前
linux查看正在运行的nginx的当前工作目录(webroot)
linux·运维·nginx
来自于狂人2 小时前
华为云Stack服务实例创建失败通用排查对照表(备考+生产故障定位必备)
服务器·数据库·华为云
QT 小鲜肉3 小时前
【Linux命令大全】001.文件管理之file命令(实操篇)
linux·运维·前端·网络·chrome·笔记