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

相关推荐
ltl6 小时前
内核追踪:ftrace、kprobe、uprobe、tracepoint 生产实战
linux
·薯条大王6 小时前
经济实惠玩云服务器|一台云服务器多人共用,子账号配置教程
java·linux·运维·服务器·汇编·c++·python
ZJH__GO9 小时前
网络编程v4pro--实现聊天室文件传输功能
java·服务器·网络·计算机网络
小小、码农9 小时前
Linux进程控制:从fork到exec,手写一个简易Shell
linux·运维·服务器
不会就选b9 小时前
Linux之进程间通信(二)---模拟进程池
linux·运维·服务器
NeilYuen10 小时前
用UDP实现向DNS服务器请求IP地址
服务器·tcp/ip·udp
沫璃染墨11 小时前
《从零入门Linux系统篇(十五):系统工具篇·六——GDB调试器详解:从程序执行控制到高级调试技巧》
linux·运维·服务器·c语言·c++
AIgorithmGEEK12 小时前
Linux 环境变量完全指南:从入门到理解底层原理
linux·运维·服务器
修罗王12 小时前
Linux Docker 服务管理与排查实战指南(新手速查版)
运维·docker
迪康Defender12 小时前
从静态存储到动态流转:终端透明加密两种模式实战解析
运维·服务器·网络·数据库·其他