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的集群与负载均衡的更多相关文章

  1. Nginx实现集群的负载均衡配置过程详解

    Nginx 的负载均衡功能,其实实际上和 nginx 的代理是同一个功能,只是把代理一台机器改为多台机器而已. Nginx 的负载均衡和 lvs 相比,nginx属于更高级的应用层,不牵扯到 ip 和 ...

  2. 在Linux上使用Nginx为Solr集群做负载均衡

    在Linux上使用Nginx为Solr集群做负载均衡 在Linux上搭建solr集群时需要用到负载均衡,但测试环境下没有F5 Big-IP负载均衡交换机可以用,于是先后试了weblogic的proxy ...

  3. 10分钟搭建服务器集群——Windows7系统中nginx与IIS服务器搭建集群实现负载均衡

    分布式,集群,云计算机.大数据.负载均衡.高并发······当耳边响起这些词时,做为一个菜鸟程序猿无疑心中会激动一番(或许这是判断是否是一个标准阿猿的标准吧)! 首先自己从宏观把控一下,通过上网科普自 ...

  4. 架构之路:nginx与IIS服务器搭建集群实现负载均衡(二)

    [前言] 在<架构之路:nginx与IIS服务器搭建集群实现负载均衡(一)>中小编简单的讲解了Nginx的原理!俗话说:光说不练假把式.接下来,小编就和大家一起来做个小Demo来体会一下N ...

  5. 架构之路:nginx与IIS服务器搭建集群实现负载均衡(三)

    参考网址:https://blog.csdn.net/zhanghan18333611647/article/details/50811980 [前言] 在<架构之路:nginx与IIS服务器搭 ...

  6. Nginx实现tomcat集群进行负载均衡

    一.背景 随着业务量和用户数量的激增,单一的tomcat部署应用已经无法满足性能需求,而且对于每次发布项目期间服务不可用的问题也凸显,既然出现了这个问题,那么我们本文就借助nginx来完美的解决这个问 ...

  7. linux下配置tomcat集群的负载均衡

    linux下配置tomcat集群的负载均衡 一.首先了解下与集群相关的几个概念集群:集群是一组协同工作的服务实体,用以提供比单一服务实体更具扩展性与可用性的服务平台.在客户端看来,一个集群就象是一个服 ...

  8. Windows7系统中nginx与IIS服务器搭建集群实现负载均衡

    10分钟搭建服务器集群——Windows7系统中nginx与IIS服务器搭建集群实现负载均衡   分布式,集群,云计算机.大数据.负载均衡.高并发······当耳边响起这些词时,做为一个菜鸟程序猿无疑 ...

  9. 搭建服务器集群——Windows7系统中nginx与IIS服务器搭建集群实现负载均衡

    转载:https://www.cnblogs.com/xiongze520/p/10308720.html 分布式,集群,云计算机.大数据.负载均衡.高并发······当耳边响起这些词时,做为一个菜鸟 ...

随机推荐

  1. 2.0 Linux系统的安装之Fedora安装单系统(2)

    2.0 Linux系统的安装之Fedora安装单系统(2) *Linux系统的安装之Fedora安装单系统 恐怕最好装的系统就是Linux系统了,或者与Windows并列.此篇教程为Fedora的单系 ...

  2. MatLab之HDL coder

    1 Workflow The workflow for applying HDL code generation to the hardware design process requires the ...

  3. SQL Server对数据进行修改

    SQL Server对数据进行修改,修改数据库中的数据. auto"> <tr style="background:red"> <td>编号 ...

  4. (转)基于Metronic的Bootstrap开发框架经验总结(6)--对话框及提示框的处理和优化

    http://www.cnblogs.com/wuhuacong/p/4775282.html 在各种Web开发过程中,对话框和提示框的处理是很常见的一种界面处理技术,用得好,可以给用户很好的页面体验 ...

  5. vue 登录验证码

    vue 登录验证码 最近在开发pc端项目,配合elementui使用 createCode() { var code = ""; var codeLength = 4; //验证码 ...

  6. PAT_A1119 Pre- and Post-order Traversals

    Source: PAT A1119 Pre- and Post-order Traversals (30 分) Description: Suppose that all the keys in a ...

  7. Selenium3+python自动化 单选框和复选框

    一.认识单选框和复选框 1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是圆的:下图复选框是方的,这个是业界的标准,要是开发小伙伴把图标弄错了,可以先抽他了. 二.radio和 ...

  8. phpcms_完整版

    {pc:content action="category" catid="0" num="6" siteid="$siteid&q ...

  9. HDU - 2973 - YAPTCHA

    先上题目: YAPTCHA Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  10. 【ACM】nyoj_7_街区最短路径问题_201308051737

    街区最短路径问题时间限制:3000 ms  |  内存限制:65535 KB 难度:4描述 一个街区有很多住户,街区的街道只能为东西.南北两种方向. 住户只可以沿着街道行走. 各个街道之间的间隔相等. ...