php负载均衡配置 及 nginx反向代理配置

目录

需求

配置步骤

结果


需求

1.单台服务器满足不了当前业务量,用多台服务器来分流

思路

1.看图片架构,本文只讲述负载均衡部分,数据库和缓存部以后更新

2.这3台web服务器怎么分配流量就靠前端的代理服务器来分配,load Balance

配置步骤

  1. 安装好nginx (自找资料,网上很多,本文用的环境是阿里云的一键安装sh-1.5.5环境)
  2. 找到nginx配置文件,我的目录是    /usr/local/nginx/conf/vhost 
  3. 将默认的project.conf拷贝一份,   命名为project.conf,   在这两台服务器上部署好自己的应用, project.conf内配置内容: 
server {
        listen       80;
        server_name  admin.xxx.com;
	    index index.html index.htm index.php;
	    root /alidata/www/proxy;

        location / {
            proxy_redirect off;
            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_pass http://monitor_server;   #这里是转发到目标地址,如果做代理,只需要把这里写上ip,做均衡就类似一个数组
        }
        location ~ .*\.(php|php5)?$
	    {
		    #fastcgi_pass  unix:/tmp/php-cgi.sock;
		    fastcgi_pass  127.0.0.1:9000;
		    fastcgi_index index.php;
		    include fastcgi.conf;
	    }
	    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
	    {
		    expires 30d;
	    }
	    location ~ .*\.(js|css)?$
	    {
		    expires 1h;
	    }
	    #伪静态规则
	    include /alidata/server/nginx/conf/rewrite/phpwind.conf;
	    access_log  /alidata/log/nginx/access/proxy.log;
    }
    upstream monitor_server {
        server xxx.xx.xxx.08:80 weight=2; #服务器1真实地址 ,weight是权重,值越大,代理服务器就会优先发给它
        server xxx.xx.xxx.09:80 weight=1; 

    }

正常可以访问

    server xxx.xx.xxx.08

    server xxx.xx.xxx.09

结果

  1. 流量器访问admin.xxx.com,会优先获取回server xxx.xx.xxx.01:80的页面,因为它的权重大.
  2. 代理转发服务器还可以做静态资源服务器.像一些css,js,image等静态资源,有些缓存静态页面也可以放在这里,这样可以加快速度

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值