Nginx HTTP负载均衡配置:
http://nginx.org/en/docs/http/load_balancing.html
负载均衡方法(算法)
RR(轮询) 依次转发
WRR(权重轮询)
最少连接数
IP-HASH 可能不均衡
环境准备:(3台机器)
LBS(负载均衡服务器)
IP:100
Nginx做负载均衡
WEB01
IP:111
Nginx作为HTTP服务
WEB02
IP:112
Nginx作为HTTP服务
Nginx配置文件修改
LBS(负载均衡服务器)
http://nginx.org/en/docs/http/load_balancing.html
选择负载均衡算法 (轮询、权重轮询 最少连接数 IP-HASH)
配置文件 xxx.conf 如下
upstream shop { # 服务器组名称
#默认使用轮询
#ip_hash
#least_conn
server 192.168.91.161 weight=x;
server 192.168.91.162 weight=y;
}
server {
listen 80;
server_name xxx.xxx.com;
access_log /var/log/nginx/lbs.access.log; #访问日志
error_log /var/log/nginx/lbs.error.log; #错误日志
location / {
proxy_pass http://shop; # 与 upstream 服务器组名一致
proxy_set_header Host $host; # Host lbs.1906.com
proxy_set_header X-Real-IP $remote_addr;
}
}
LBS的nginx配置例子:
upstream shop {
server 192.168.235.111; //两台web服务器的IP
server 192.168.235.122;
}
server {
listen 80;
server_name shop.1906.com; //域名
access_log logs/lbs.1906.access.log; #访问日志
error_log logs/lbs.1906.error.log; #错误日志
location / {
proxy_set_header Host $host;
proxy_pass http://shop;
}
}
web1的nginx配置:
server {
listen 80;
server_name shop.1906.com;
access_log logs/lbs.1906.access.log; #访问日志
error_log logs/lbs.1906.error.log; #错误日志
location / {
root /wwwroot/1906shop/public;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
root /wwwroot/1906shop/public;
fastcgi_pass 127.0.0.1:9000; # PHP-FPM
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
web2的nginx配置:
server {
listen 80;
server_name shop.1906.com;
access_log logs/lbs.1906.access.log; #访问日志
error_log logs/lbs.1906.error.log; #错误日志
location / {
root /wwwroot/1906shop/public;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
root /wwwroot/1906shop/public;
fastcgi_pass 127.0.0.1:9000; # PHP-FPM
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
- 重要文档
- 工作须知
- 项目下的公共方法
- 程序员给代码写注释时有哪些讲究!
- RestFul 讲解
- 其他知识
- docker容器
- MongoDB的使用
- Node.js的使用
- Session共享
- Wordpress的使用
- Websocket的简介
- Ajax
- 项目技术
- Https配置证书
- Nginx的反向代理
- MySQL读写分离配置(laravel篇)
- Nginx的负载均衡
- App接口返回格式
- laravel中JWT的应用
- laravel验证码的使用
- laravel公共方法文件
- laravel框架的RBAC
- Git相关
- Git篇1
- Git篇2
- Mysql相关
- Mysql的主从复制
- MySQL的备份
- MySQL的使用
- 请求第三方接口
- Redis相关
- redis的使用
- Redis的基本用法以及场景分析
- 开发小技巧
- Linux
- 禁用root及密码登录
- Lnmp环境的安装
- 安装composer
- 安装Redis
- 文件共享服务 samba
- 其他安装
- Lnmp常用命令
- 性能检测命令
- Nginx的配置详解
- PHP相关
- PHP基础知识
- php常见的系统函数
- PHP的设计模式
- Cookie 和 Session 的封装
- Mysql知识
- Mysql索引
- MySQL的数据类型
- PHP重要知识
- PHP框架篇
- Laravel框架
- laravel---Excel
- laravel文件上传
- Laravel-Mysql常用操作
- Laravel队列(queue)
- laravel-发送Email
- laravel--JWT
- TP框架篇
- tp5主从数据库设置读写分离
- 前端
- JS
- js代码实现点击按钮出现60秒倒计时
- 开发软件相关
- 代码编辑器
- vs code配置ftp连接远程服务器实现代码文自动上传
- 编程相关软件下载