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

相关推荐
网络笨猪3 小时前
# Nginx企业级全套配置\+排错手册
运维·nginx
Yupureki4 小时前
《Linux网络编程》8.网络层IP原理
linux·运维·服务器·网络·ip
大厂数码评测员4 小时前
免费菜谱管理小程序怎么做才顺手:从情侣、个人、家庭三类场景拆需求和实现
服务器·小程序·apache
yyuuuzz4 小时前
aws亚马逊入门常见认知误区
运维·服务器·网络·云计算·github·aws
Je1lyfish4 小时前
CMU15-445 (2025 Fall/2026 Spring) Project#3 - QueryExecution
linux·c语言·开发语言·数据结构·数据库·c++·算法
DeepFlow 零侵扰全栈可观测4 小时前
运动战:AI 时代 IT 运维的决胜之道——DeepFlow 业务全链路可观测性的落地实践
运维·网络·人工智能·arcgis·云计算
林叔聊渠道分销5 小时前
saas产品运营案例 | 联盟营销计划如何帮助企业提高销售额?
运维·产品运营·sass·流量运营·用户运营
eucalyptus-DE7 小时前
Nova 计算节点故障排查指南
服务器·openstack
志栋智能7 小时前
告别报告堆砌:超自动化巡检的智能分析与洞察
运维·服务器·网络·人工智能·自动化
xyy_4967 小时前
wsl-localhost
linux