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

查看服务

相关推荐
初级炼丹师(爱说实话版)13 小时前
Ubuntu服务器配置docker
服务器·ubuntu·docker
是良辰16 小时前
Docker Nginx HTTPS 自签证书部署完整操作文档
nginx·docker·https
bellus-17 小时前
Ubuntu 26.04 Miniforge3 安装与配置完整指南
linux·运维·ubuntu
今天AI了吗18 小时前
OpenCode AI 编程:Ubuntu 24.04 环境安装与使用指南
linux·人工智能·ubuntu
用什么都重名18 小时前
Ubuntu 24.04 安装 NVIDIA 驱动:解决 “NVIDIA-SMI has failed“ 报错全记录
linux·运维·ubuntu
bosins19 小时前
Ubuntu 日常最常用的文件操作场景和对应指令
linux·服务器·ubuntu
PinoLio19 小时前
鲁班猫5-实战篇之虚拟机运行yolov5
yolo·ubuntu
難釋懷20 小时前
Nginx外置缓存-redis2-nginx-module
nginx·缓存·junit
啦啦啦!21 小时前
虚拟机如何接入Codex并配置中转站(vscode插件版)
linux·vscode·ubuntu·编辑器
小张同学a.21 小时前
LAMP架构4——MySQL高可用
linux·运维·服务器·数据库·mysql·架构·负载均衡