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 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的