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)
}