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

相关推荐
snow@li15 分钟前
CA证书是什么/数字证书/互联网上的电子身份证/Certificate Authority
运维
企鹅的蚂蚁32 分钟前
LubanCat RK3588 实时 Linux 开发(九):从 U-Boot 到 initramfs 的串口启动故障分析
linux·rk3588·u-boot·串口调试·initramfs·linux启动
Wang's Blog39 分钟前
Java框架快速入门: Spring Security+OAuth2之搭建授权服务器(依赖与表结构)
java·服务器·spring
kkkkkkkkkk_Z1 小时前
学嵌入式和Linux应用编程|学习日记:UDP协议与Wireshark抓包学习笔记
linux·笔记·学习
Allstar_431 小时前
全星研发项目管理APQP系统支持本地/私有云,开放API对接ERP/MES/PLM/OA,分级权限、版本追溯、ECN闭环,低代码配置,便于研发质量一体化扩展
运维
嵌入式小能手1 小时前
飞凌嵌入式ElfBoard-Shell编程应用实例-提取字符并设置rtc时间
linux
刃神太酷啦1 小时前
Redis 核心进阶:哨兵、集群、缓存问题与分布式锁详解----《Hello Redis!》(6)
linux·c语言·数据库·c++·redis·分布式·缓存
大卡片2 小时前
LCD相关知识
linux
colourmind2 小时前
K3S+Hami+Higress+Vip(nginx+keepalived)搭建云原生高可用的大模型部署平台
运维·nginx·云原生
闲云野鹤在人间2 小时前
Docker入门|第3章 镜像详解
linux·网络·docker·容器·centos·云计算·php