nginx fastcgi负载均衡

 

当后端某机器无法连接,或者处理fastcgi请求时异常退出,nginx会将fastcgi请求发送到另外一台机器。

 

配置文件

 

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;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

        upstream backend {  //配置后端机器
                server 192.168.22.103:9000;
                server 172.28.250.130:9901;
        }

    server {
        listen       8099;
            upstream backend {
                server 192.168.22.103:9000;
                server 172.28.250.130:9901;
                }
        .......

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           html;
            fastcgi_pass   backend; //指定到后端机器
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
        
        ...............

 

2017/10/11 11:12:21 [debug] 24481#0: *66 http upstream request: "/aa.php?"
2017/10/11 11:12:21 [debug] 24481#0: *66 http upstream process header
2017/10/11 11:12:21 [debug] 24481#0: *66 malloc: 0000000006717E30:4096
2017/10/11 11:12:21 [debug] 24481#0: *66 recv: fd:4 0 of 4096
2017/10/11 11:12:21 [error] 24481#0: *66 upstream prematurely closed connection while reading response header from upstream, client: 192.168.22.103, server: localhost, request: "GET /aa.php HTTP/1.1", upstream: "fastcgi://192.168.22.103:9000", host: "172.28.250.184:8099"
2017/10/11 11:12:21 [debug] 24481#0: *66 http next upstream, 2
2017/10/11 11:12:21 [debug] 24481#0: *66 free rr peer 2 4
2017/10/11 11:12:21 [warn] 24481#0: *66 upstream server temporarily disabled while reading response header from upstream, client: 192.168.22.103, server: localhost, request: "GET /aa.php HTTP/1.1", upstream: "fastcgi://192.168.22.103:9000", host: "172.28.250.184:8099"
2017/10/11 11:12:21 [debug] 24481#0: *66 free rr peer failed: 0000000006738850 0
2017/10/11 11:12:21 [debug] 24481#0: *66 close http upstream connection: 4
2017/10/11 11:12:21 [debug] 24481#0: *66 free: 00000000066F71D0, unused: 48
2017/10/11 11:12:21 [debug] 24481#0: *66 event timer del: 4: 1507691601518
2017/10/11 11:12:21 [debug] 24481#0: *66 reusable connection: 0
2017/10/11 11:12:21 [debug] 24481#0: *66 get rr peer, try: 1
2017/10/11 11:12:21 [debug] 24481#0: *66 get rr peer, current: 00000000067388F8 0
2017/10/11 11:12:21 [debug] 24481#0: *66 stream socket 4
2017/10/11 11:12:21 [debug] 24481#0: *66 epoll add connection: fd:4 ev:80000005
2017/10/11 11:12:21 [debug] 24481#0: *66 connect to 172.28.250.130:9901, fd:4 #68
2017/10/11 11:12:21 [debug] 24481#0: *66 http upstream connect: -2
2017/10/11 11:12:21 [debug] 24481#0: *66 posix_memalign: 00000000066F71D0:128 @16
2017/10/11 11:12:21 [debug] 24481#0: *66 event timer add: 4: 60000:1507691601519
2017/10/11 11:12:21 [debug] 24481#0: epoll: stale event 00002AD1E49F92B0
2017/10/11 11:12:21 [debug] 24481#0: timer delta: 1
2017/10/11 11:12:21 [debug] 24481#0: worker cycle
2017/10/11 11:12:21 [debug] 24481#0: epoll timer: 60000
2017/10/11 11:12:21 [debug] 24481#0: epoll: fd:4 ev:0019 d:00002AD1E49F92B1
2017/10/11 11:12:21 [debug] 24481#0: epoll_wait() error on fd:4 ev:0019
2017/10/11 11:12:21 [debug] 24481#0: *66 http upstream request: "/aa.php?"
2017/10/11 11:12:21 [debug] 24481#0: *66 http upstream process header
2017/10/11 11:12:21 [error] 24481#0: *66 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.22.103, server: localhost, request: "GET /aa.php HTTP/1.1", upstream: "fastcgi://172.28.250.130:9901", host: "172.28.250.184:8099"
2017/10/11 11:12:21 [debug] 24481#0: *66 http next upstream, 2
2017/10/11 11:12:21 [debug] 24481#0: *66 free rr peer 1 4
2017/10/11 11:12:21 [warn] 24481#0: *66 upstream server temporarily disabled while connecting to upstream, client: 192.168.22.103, server: localhost, request: "GET /aa.php HTTP/1.1", upstream: "fastcgi://172.28.250.130:9901", host: "172.28.250.184:8099"
2017/10/11 11:12:21 [debug] 24481#0: *66 free rr peer failed: 00000000067388F8 0
2017/10/11 11:12:21 [debug] 24481#0: *66 finalize http upstream request: 502
2017/10/11 11:12:21 [debug] 24481#0: *66 finalize http fastcgi request
2017/10/11 11:12:21 [debug] 24481#0: *66 close http upstream connection: 4
2017/10/11 11:12:21 [debug] 24481#0: *66 free: 00000000066F71D0, unused: 48
2017/10/11 11:12:21 [debug] 24481#0: *66 event timer del: 4: 1507691601519
2017/10/11 11:12:21 [debug] 24481#0: *66 reusable connection: 0
2017/10/11 11:12:21 [debug] 24481#0: *66 http finalize request: 502, "/aa.php?" a:1, c:1
2017/10/11 11:12:21 [debug] 24481#0: *66 http special response: 502, "/aa.php?"
2017/10/11 11:12:21 [debug] 24481#0: *66 internal redirect: "/50x.html?"

 

posted on 2017-10-11 11:20  阮減显  阅读(904)  评论(0编辑  收藏  举报

导航