doudi8829 2016-08-31 15:49
浏览 450

即使保持活动状态,Nginx也会关闭连接

So I have an issues which I'm not sure if it's a GO problem or issues with nginx configuration. Basically when trying to test a curl request to our servers, the connection unexpectedly gets closed, even though keep-alive is set to true. Below is the log I get back from nginx:

* About to connect() to sub.domain.com port 80 (#0)
* Trying W.X.Y.Z... connected
> POST /br HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: sub.domain.com
> Accept: */*
> Connection: keep-alive
> Content-Length: 1635
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Date: Wed, 31 Aug 2016 15:31:21 GMT
< Server: nginx/1.6.1
< Content-Length: 3158
< Connection: keep-alive
<
{"data1": "some data", "data2": "some data2" ....
* Connection #0 to host sub.domain.com left intact
* Closing connection #0
... "dataX": "some dataX", "dataY": "some dataY}

Our nginx keep-alive configuration:

keepalive_timeout 150;
keepalive_requests 5000;

The nginx is sitting in front of a Go server, although it shouldn't impact it. Any tips on how to go about trying to figure out why the keep-alive is closing the connection?

Edit: complete nginx config:

user  nginx;
worker_processes  auto;
worker_rlimit_nofile 200000;

pid        /var/run/nginx.pid;

events {
    worker_connections 60000;
    multi_accept on;
}

http {
    include       /etc/nginx/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"';

    error_log   /dev/null;
    access_log   /dev/null;

    sendfile        on;
    tcp_nopush     on;

    keepalive_timeout 150;
    keepalive_requests 5000;
    client_header_timeout 2;
    client_body_timeout 2;

    reset_timedout_connection on;
    send_timeout 2;
    gzip  on;

    include /etc/nginx/conf.d/*.conf;

    upstream go_app {
    server 127.0.0.1:3000 weight=1;
    keepalive 2000;
    }

    server {
        listen 80;
        server_name 1.domain.com 2.domain.com 3.domain.com 4.domain.com 5.domain.com;
        location / {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header HOST $http_host;
                proxy_set_header X-NginX-Proxy true;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://go_app;
                proxy_redirect off;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }
    }


    server {
        listen       80;
        server_name  localhost;
        root         /usr/share/nginx/html;

        location / {
        }

        error_page  404              /404.html;
        location = /40x.html {
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        }
    }
}

And the go-code responsible for writing the response:

func Success(response http.ResponseWriter, value string) {
    response.Header().Set("Content-Type", "application/json; charset=utf-8")
    fmt.Fprint(response, value)
    response.Write(nil)
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛