UBUNTU中nginx反向代理(负载均衡)

现有三台虚拟机(ubuntu、centos7、centos8)

centos 7安装apache(192.168.100.88:80)

yum install -y httpd

启动服务并设置开机自启

systemctl start httpd

systemctl enable httpd

关闭防火墙、关闭沙盒

systemctl stop firewalld

setenforce 0

验证是否运行成功

systemctl status httpd

页面验证

centos8 安装 Apache (192.168.100.91:80)

dnf install -y httpd

启动

httpd systemctl start httpd

设置开机自启

systemctl enable httpd

查看运行状态

systemctl status httpd

关闭防火墙、关闭沙盒

systemctl stop firewalld

setenforce 0

验证

ubuntu安装nginx(192.168.100.99:80)

更新系统软件源

apt update

apt upgrade -y

安装 Nginx

apt install nginx -y

检查 Nginx 是否运行

systemctl status nginx

放行防火墙(或者关闭ufw)

ufw allow 'Nginx Full'

配置代理负载文件(若是其他的系统,寻找相对应的本地配置文件修改)

vim /etc/nginx/sites-available/default

upstream backend_servers {

负载均衡策略

server 192.168.100.88:80; # 后端服务1

server 192.168.100.91:80; # 后端服务2

ip_hash; # IP 绑定(会话保持)

least_conn; # 最少连接

weight 轮询示例

server 127.0.0.1:8080 weight=5;

server 127.0.0.1:8081 weight=3;

}

server {

listen 80;

server_name _;

location / {

proxy_pass http://backend_servers;

传递真实IP

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

超时

proxy_connect_timeout 5s;

proxy_read_timeout 10s;

proxy_send_timeout 10s;

}

}

:wq 保存退出

重启服务

systemctl restart nginx

查看服务

相关推荐
迷茫的大专生3 小时前
高可用总结
redis·mysql·nginx·高可用
问简4 小时前
【ubuntu】在 Ubuntu 26 上屏蔽 Windows 盘
ubuntu
szephyr5 小时前
Nginx 反向代理实战:从 502、跨域到 HTTPS,一次打通
运维·nginx·https·部署·反向代理
迷茫的大专生5 小时前
服务器部署与 MySQL 运维学习笔记:从 Ansible 到高可用与性能优化
mysql·nginx·ansible·mysql优化·keepalive
程曦曦5 小时前
MySQL 生产库误删 98 张表后的时间点恢复实战:从 binlog 解析到资金对账
linux·数据结构·其他·算法·ubuntu·运维开发
A心有千千结7 小时前
Nginx网关可观测建设:打通流量入口,加速线上故障诊断
nginx·prometheus·devops
程序员大阳9 小时前
使用Putty登录阿里云Ubuntu ECS服务器方法
ubuntu·云计算·ssh·ecs·putty
Anthony_2319 小时前
Nginx基础
服务器·nginx·http·https·edge浏览器·web
网硕互联的小客服10 小时前
如何在Ubuntu系统上查看和刷新DNS缓存?操作方法与原理解析
运维·服务器·网络·ubuntu
八年。。10 小时前
WSL学习(三)——搭建Linux + C++ + SOME/IP 基础开发环境
开发语言·笔记·ubuntu