您当前的位置: 首页 >  负载均衡

苗先生的PHP记录

暂无认证

  • 0浏览

    0关注

    190博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

使用nginx负载均衡upstream分发请求地址到hyperf项目

苗先生的PHP记录 发布时间:2022-10-18 16:48:39 ,浏览量:0

宝塔环境: centos7 + php8.1 + nginx1.2 + swoole4 + hyperf3.0

这里主要是配置分发负载均衡 , 只是轮询 , 其他模式如 iphash 权重等 , 自行查找资料修改upstream

1. 首先在nginx主配置文件中添加

	upstream ddgcjx {
            server 127.0.0.1:9501;
            server 127.0.0.1:9502;
            keepalive 32;
        }

 这里upstream后面是自定义的名字 , 后面proxy_pass得和这里对应上

 这里是加在http 模块下 , nginx配置文件中的结构如下

events

{

```

}

http

{

````

    upstream ddgcjx {             server 127.0.0.1:9501;             server 127.0.0.1:9502;             keepalive 32;         }

     server

     {

     }   

}

2.  在网站的配置文件中修改成下面这样子

server
{
    listen 80;
    server_name msy2.cn;
  
    location / {
        proxy_pass http://ddgcjx;
        
           # 代理真实请求ip
        # proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

  
	access_log  /www/wwwlogs/msy2.cn.log;
    error_log  /www/wwwlogs/msy2.cn.error.log;
}

3. 重启nginx

4. 修改两个项目访问结果不一致 , 查看请求

eg: 查找资料

分发方式搜索    nginx upstream 负载均衡  等关键字

分发匹配搜索    nginx location 

分发网址参数    nginx proxy详解  proxy参数 等关键字

关注
打赏
1665468453
查看更多评论
立即登录/注册

微信扫码登录

0.0417s