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

相关推荐
Nick.Q18 分钟前
CentOS 8 离线安装beyond compare
linux·centos
鹿鸣天涯20 分钟前
openEuler学习笔记1-openEuler前世今生
linux·openeuler
pwn蒸鱼43 分钟前
buuctf中的mrctf2020_shellcode
linux·安全
夕除44 分钟前
java--1
linux·运维·服务器
桌面运维家1 小时前
vDisk VOI桌面安全策略怎么配置?详细教程
运维·网络
重生之绝世牛码1 小时前
Linux软件安装 —— ClickHouse单节点安装(rpm安装、tar安装两种安装方式)
大数据·linux·运维·数据库·clickhouse·软件安装·clickhouse单节点
莫问前路漫漫1 小时前
Electerm 连接远程服务器完整指南
运维·服务器·git
苏宸啊1 小时前
Linux下diy程序:进度条
linux·运维·服务器
70asunflower1 小时前
Python with 语句与上下文管理完全教程
linux·服务器·python
tritone1 小时前
学习Chef自动化配置管理工具,为了实践环境部署,我选择了**阿贝云**的**免费虚拟主机**和**免费云服务器**来搭建测试平台。
服务器·学习·自动化