nginx 负载均衡

2017-07-13 10:29:18 +08:00
 iguoji

三台服务器

主 174 装 NGINX

从 170,191 装 PHP

三台服务器防火墙和 SELINUX 都已经关闭了

主服务器装好 Nginx 后,直接访问能看到欢迎页面

从服务器装好 php 后,直接用 PHP -S ip:port 启动,访问能看到正常页面

三台服务器的 /home/wwwroot 目录下分别有几个相同的测试文件

主服务器 174

nginx/conf.d/default.conf

upstream myServer{
    server 192.168.199.191:9000 max_fails=3 fail_timeout=10s;
    server 192.168.199.170:9000 max_fails=3 fail_timeout=10s;
}
server {
    listen       80;
    server_name  192.168.199.174;
    location / {
        root   /home/wwwroot;
        index  index.html index.htm;
    }
    location ~ \.php$ {
        root           /home/wwwroot;
        fastcgi_pass   myServer;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

从服务器 170 191

/usr/local/etc/php-fpm.d/www.conf

[www]
; 担心是用户权限问题,所以把 nobody 改成了 root
; 用 php-fpm -R 启动
user = root
group = root

listen = [::]:9000
listen.allowed_clients = any
request_terminate_timeout = 0

但最终结果是:

2017/07/13 10:28:10 [error] 2199#2199: *10 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.199.222, server: 192.168.199.174, request: "GET /1.php HTTP/1.1", upstream: "fastcgi://192.168.199.191:9000", host: "192.168.199.174"
2017/07/13 10:28:10 [warn] 2199#2199: *10 upstream server temporarily disabled while reading response header from upstream, client: 192.168.199.222, server: 192.168.199.174, request: "GET /1.php HTTP/1.1", upstream: "fastcgi://192.168.199.191:9000", host: "192.168.199.174"
2017/07/13 10:28:10 [error] 2199#2199: *10 upstream prematurely closed connection while reading response header from upstream, client: 192.168.199.222, server: 192.168.199.174, request: "GET /1.php HTTP/1.1", upstream: "fastcgi://192.168.199.170:9000", host: "192.168.199.174"
2017/07/13 10:28:10 [warn] 2199#2199: *10 upstream server temporarily disabled while reading response header from upstream, client: 192.168.199.222, server: 192.168.199.174, request: "GET /1.php HTTP/1.1", upstream: "fastcgi://192.168.199.170:9000", host: "192.168.199.174"

求问,毛病出在那里?

3210 次点击
所在节点    程序员
5 条回复
iguoji
2017-07-13 10:31:48 +08:00
```
2017/07/13 10:31:15 [error] 2199#2199: *13 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.199.222, server: 192.168.199.174, request: "GET /1.php HTTP/1.1", upstream: "fastcgi://192.168.199.170:9000", host: "192.168.199.174"
2017/07/13 10:31:15 [warn] 2199#2199: *13 upstream server temporarily disabled while reading response header from upstream, client: 192.168.199.222, server: 192.168.199.174, request: "GET /1.php HTTP/1.1", upstream: "fastcgi://192.168.199.170:9000", host: "192.168.199.174"
2017/07/13 10:31:15 [error] 2199#2199: *13 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.199.222, server: 192.168.199.174, request: "GET /1.php HTTP/1.1", upstream: "fastcgi://192.168.199.191:9000", host: "192.168.199.174"
2017/07/13 10:31:15 [warn] 2199#2199: *13 upstream server temporarily disabled while reading response header from upstream, client: 192.168.199.222, server: 192.168.199.174, request: "GET /1.php HTTP/1.1", upstream: "fastcgi://192.168.199.191:9000", host: "192.168.199.174"
```
akrf
2017-07-13 10:43:01 +08:00
listen = [::]:9000

这是 ipv6 的 any ip 吧。。。用 0.0.0.0 的 ipv4 any ip 试试。。。
iguoji
2017-07-13 10:45:29 +08:00
@akrf 原本写的是 listen = 192.168.199.xx:9000,后面发现不行才改成这样的
oksbsb
2017-07-13 11:21:42 +08:00
174 跑 php 修改 fastcgi_pass myServer; 指向本机试试
iguoji
2017-07-13 11:32:20 +08:00
@oksbsb

找到原因了,listen.allowed_clients = any,这个东西的锅。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/374983

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX