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

相关推荐
你住过的屋檐40 分钟前
【SeaweedFS】Linux上搭建SeaweedFS文件存储服务完整教程
linux·运维·服务器
Decay__1 小时前
PostgreSQL 体系架构全解 —— 进程模型、共享内存、MVCC 与 WAL 预写日志深入
运维·数据库·sql·mysql·架构
少司府1 小时前
嵌入式外设篇(三)GPIO·三:MCU系统结构、总线与统一编制
linux·python·stm32·单片机·嵌入式硬件·mcu·嵌入式软件
分布式存储与RustFS2 小时前
桶里的文件想当目录使:用 ZeroFS 把 RustFS 挂成一棵 POSIX 树
运维·云原生·开源·对象存储·分布式存储·s3·性能基准
老余说AI2 小时前
跨境电商、课程出海:六款多语言视频翻译工具选型指南
大数据·运维·人工智能
不积跬步无以至千里mmbb262 小时前
Rust三大核心:Trait Crate Mod详解
linux·rust
分布式存储与RustFS3 小时前
向量表别堆本地盘:用 LanceDB 把数据集建在 RustFS 上
运维·云原生·开源·对象存储·分布式存储·s3·性能基准
2401_868534783 小时前
天融信网络安全面试题
服务器·网络
无忧.芙桃17 小时前
Linux系统编程(四):用户与权限管理
linux·运维·服务器
最强小杰18 小时前
某 OpenAI 兼容网关上的 `kimi-k3.1-pro`:Cline、Zed 接入与 SSE 排错示例
java·服务器·网络·ai