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

相关推荐
maosheng11463 分钟前
linux的综合教程(搭建论坛教程)
linux
IpdataCloud6 分钟前
效果广告中点击IP与转化IP不一致?用IP查询怎么做归因分析?
运维·服务器·网络
Deitymoon17 分钟前
linux——TCPIP协议原理
linux·网络
独小乐26 分钟前
018.使用I2C总线EEPROM|千篇笔记实现嵌入式全栈/裸机篇
linux·笔记·单片机·嵌入式硬件·arm·信息与通信
SPC的存折36 分钟前
2、Docker命令与镜像、容器管理
linux·运维·服务器·docker·容器·eureka
D4c-lovetrain40 分钟前
Linux个人心得26 (redis主从复制全流程,详细版)
linux·运维·服务器
晴天¥1 小时前
达梦数据库共享存储集群搭建(DSC双节点+Openfiler-IP SAN存储)
linux·数据库·达梦数据库
吃着火锅x唱着歌1 小时前
LeetCode 150.逆波兰表达式求值
linux·算法·leetcode
Bert.Cai1 小时前
Linux whoami命令详解
linux·运维
x***r1511 小时前
驱动精灵离线版使用指南:免联网快速安装驱动(万能网卡版)
linux·运维·服务器