Linux - Nginx的集群与负载均衡
Nginx的集群与负载均衡
集群就是一群人干同样的活,负载均衡就是保证每个人都干得差不多。或者大人干得多一些,小孩干得少一些。
Nginx实现负载均衡很方便。
准备三台服务器,一台是用于访问图片(66)。另外是两台用于提供图片服务的集群(61,62)。
先准备三个logo.png图片。
66上如下:
61上如下:
62上如下:
设置图片组66:
upstream imgserver {
server 192.168.70.61:80 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.70.62:80 weight=1 max_fails=2 fail_timeout=30s;
}
处理反向代理:
location ~ .*\.(jpg|jpeg|png|gif)$ {
proxy_pass http://imgserver;
proxy_set_header X-Forwarded-For $remote_addr;
}
下面是完整的配置。
#user nobody;
user nginx nginx; # 指定Nginx服务的用户和用户组
worker_processes auto;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
server_tokens off;
sendfile on;
#tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 65;
send_timeout 30;
gzip on;
upstream imgserver {
server 192.168.70.61:80 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.70.62:80 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;
charset UTF-8;
#charset koi8-r;
#access_log logs/host.access.log main;
set $root /var/webroot/tp5admin;
location / {
root $root;
index index.php index.html index.htm;
if ( -f $request_filename) {
break;
}
if ( !-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
}
location ~ .*\.(jpg|jpeg|png|gif)$ {
proxy_pass http://imgserver;
proxy_set_header X-Forwarded-For $remote_addr;
}
location ~ .*\.(js|css)$ {
proxy_pass http://192.168.70.62:80;
proxy_set_header X-Forwarded-For $remote_addr;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/webroot;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php(.*)$ {
root $root;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT$fastcgi_script_name;
fastcgi_param PATH_INFO $1; # 把pathinfo部分赋给PATH_INFO变量
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
server {
listen 81;
server_name localhost:81;
set $root /var/webroot;
location / {
root $root;
index index.php index.html index.htm;
if ( -f $request_filename) {
break;
}
if ( !-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/webroot;
}
location ~ .+\.php($|/) {
root $root;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
include fastcgi_params;
}
}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
Linux - Nginx的集群与负载均衡的更多相关文章
- Nginx实现集群的负载均衡配置过程详解
Nginx 的负载均衡功能,其实实际上和 nginx 的代理是同一个功能,只是把代理一台机器改为多台机器而已. Nginx 的负载均衡和 lvs 相比,nginx属于更高级的应用层,不牵扯到 ip 和 ...
- 在Linux上使用Nginx为Solr集群做负载均衡
在Linux上使用Nginx为Solr集群做负载均衡 在Linux上搭建solr集群时需要用到负载均衡,但测试环境下没有F5 Big-IP负载均衡交换机可以用,于是先后试了weblogic的proxy ...
- 10分钟搭建服务器集群——Windows7系统中nginx与IIS服务器搭建集群实现负载均衡
分布式,集群,云计算机.大数据.负载均衡.高并发······当耳边响起这些词时,做为一个菜鸟程序猿无疑心中会激动一番(或许这是判断是否是一个标准阿猿的标准吧)! 首先自己从宏观把控一下,通过上网科普自 ...
- 架构之路:nginx与IIS服务器搭建集群实现负载均衡(二)
[前言] 在<架构之路:nginx与IIS服务器搭建集群实现负载均衡(一)>中小编简单的讲解了Nginx的原理!俗话说:光说不练假把式.接下来,小编就和大家一起来做个小Demo来体会一下N ...
- 架构之路:nginx与IIS服务器搭建集群实现负载均衡(三)
参考网址:https://blog.csdn.net/zhanghan18333611647/article/details/50811980 [前言] 在<架构之路:nginx与IIS服务器搭 ...
- Nginx实现tomcat集群进行负载均衡
一.背景 随着业务量和用户数量的激增,单一的tomcat部署应用已经无法满足性能需求,而且对于每次发布项目期间服务不可用的问题也凸显,既然出现了这个问题,那么我们本文就借助nginx来完美的解决这个问 ...
- linux下配置tomcat集群的负载均衡
linux下配置tomcat集群的负载均衡 一.首先了解下与集群相关的几个概念集群:集群是一组协同工作的服务实体,用以提供比单一服务实体更具扩展性与可用性的服务平台.在客户端看来,一个集群就象是一个服 ...
- Windows7系统中nginx与IIS服务器搭建集群实现负载均衡
10分钟搭建服务器集群——Windows7系统中nginx与IIS服务器搭建集群实现负载均衡 分布式,集群,云计算机.大数据.负载均衡.高并发······当耳边响起这些词时,做为一个菜鸟程序猿无疑 ...
- 搭建服务器集群——Windows7系统中nginx与IIS服务器搭建集群实现负载均衡
转载:https://www.cnblogs.com/xiongze520/p/10308720.html 分布式,集群,云计算机.大数据.负载均衡.高并发······当耳边响起这些词时,做为一个菜鸟 ...
随机推荐
- Django学习案例一(blog):六. 开发博客内容页面
目标:某条博客具体内容的展示,可返回博客主页面,可进行评论. 1. 编辑路由 一篇博客,要将其找出来,就需要有一个唯一的标识.Django 的模型中默认有一个唯一的且未自增长的主键,即 id 字段.我 ...
- 易企CMS仿站标签说明
头部标签: 每个页面都必须加的三大标签(将标签放入header.tpl里面,这样只需在每个模板中调用header.tpl即可): <title>{$seotitle}_{$sitename ...
- 10--C++多态
C++多态 C++多态技术 摘要 本文描述了C++中的各种多态性.重点阐述了面向对象的动态多态和基于模板的静态多态,并初步探讨了两种技术的结合使用. 关键词 多态 继续 虚函数 模板 宏 函 ...
- mvc自定义控件
//自定义一个DatePicker.cshtml文件@helper Init() { <link href="~/Content/mobiscroll.custom-2.5.0.min ...
- jq 禁用复选框 和输入框
$('input').attr("readonly", ""); $('input').attr("disabled", "fal ...
- 使用JAVA写一个简单的日历
JAVA写一个简单的日历import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateF ...
- ListUtil集合操作常用方法类
* 集合操作常用方法类. * <p> * * @author 柯 */ public class ListUtil { /** * 判断List不为空,非空返回true,空则返回false ...
- CallableStatement的用法
CallableStatement 对象为所有的 DBMS 提供了一种以标准形式调用已储存过程的方法.已储存过程储存在数据库中.对已储存过程的调用是 CallableStatement 对象所含的内容 ...
- Python笔记(29)----进程
目录: 一.进程 多任务的概念 创建子进程----fork[Linux] 全局变量在多个进程中不共享 多次fork() 创建进程----multiprocessing[windows] 二.线程 一. ...
- 【剑指Offer】37、数字在排序数组中出现的次数
题目描述: 统计一个数字在排序数组中出现的次数.例如,输入排序数组{1,2,3,3,3,3,4,5}和数字3,由于数字3在该数组中出现了4次,所以函数返回4. 解题思路: 既然输入的数 ...