【发布时间】:2020-03-11 02:53:30
【问题描述】:
我正在使用 Flask 运行 python(3.6)。它在uwsgi 后面运行。我需要在这个应用程序上启用 keep-alive,所以我在 uwsgi 命令上添加了--so-keepalive 参数,如下所示:
uwsgi \
--uid uwsgi \
--master \
--http :8080 \
--enable-threads \
--so-keepalive \
--wsgi-file api/uwsgi.py
当检查请求响应标头时,keep-alive 不会出现。它仅出现在请求标头上。响应头是:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 99
我使用curl来测试连接:
curl -Iv http://localhost:9301/v2/health --next http://localhost:9301/v2/health
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9301 (#0)
> HEAD /v2/health HTTP/1.1
> Host: localhost:9301
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Content-Type: application/json
Content-Type: application/json
< Content-Length: 5
Content-Length: 5
<
* Connection #0 to host localhost left intact
* Found bundle for host localhost: 0x7fb4db60b7d0 [can pipeline]
* Could pipeline, but not asked to!
* Connection 0 seems to be dead!
* Closing connection 0
* Hostname localhost was found in DNS cache
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9301 (#1)
> GET /v2/health HTTP/1.1
> Host: localhost:9301
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json
< Content-Length: 5
<
"OK"
* Connection #1 to host localhost left intact
* Closing connection 1
您可以看到它创建了两个连接#0 和#1。我的服务器上似乎没有使用保持连接。
我想知道我的应用程序是否启用了 keep-alive?如何启用它?
【问题讨论】: