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

相关推荐
aixingkong9212 小时前
AI超节点Scale Up域总线各层优化设计
linux·服务器·网络
kidwjb3 小时前
Linux内核-文件系统-文件系统目录和文件操作
linux·内核·文件系统
yj_xqj3 小时前
Docker 基础应用与介绍
运维·docker·容器
_艾伦 耶格尔.3 小时前
进程控制
linux
happymagic4 小时前
vmware workstation Pro 虚拟机设定启停的时间段
运维·服务器·windows
寒水馨4 小时前
Linux下载、安装PowerShell-v7.6.4(附安装包powershell-7.6.4-linux-x64.tar.gz)
linux·跨平台·自动化运维·devops·命令行·powershell·脚本语言
一只鹿鹿鹿4 小时前
三甲综合智慧医院信息化总体解决方案(PPT文件)
大数据·运维·物联网·安全·政务
AI的探索之旅4 小时前
BOM管理的AI自动化:从原理图到采购清单,我搭了一套全自动工具链
运维·人工智能·自动化
组合缺一4 小时前
Solon 的 10 种 HTTP 服务器:改一行依赖,换一个引擎
java·服务器·网络协议·http·solon
lsh曙光4 小时前
scp和rsync远程同步
linux