首页 > 解决方案 > Apollo graphql 和 Nginx 的空响应

问题描述

我们的应用程序通过 Apollo、Express 和 Nest.js 公开了一个 graphql API。在 prod/staging 环境中,应用程序部署在 Nginx 入口(kubernetes)后面。API 在生产环境和kubectl port-forward. 但是,当我们尝试使用 Nginx 背后的 API 时,当响应负载高于大约 1 KB 时,HTTP 响应会挂起(TCP 超时)。我们有一些结论:

因此,这似乎是与作为代理的 Nginx 与 Apollo 服务器之间的集成有关的问题。有人对此有任何想法吗?

这是导致问题的 curl 请求的示例:

 $ curl -v --location --request POST 'https://my-company.com/graphql' --header 'Content-Type: application/json' --data-raw '{"query":"query {\n  myQueryHere \n}","variables":{}}'
  Note: Unnecessary use of -X or --request, POST is already inferred.
  *   Trying <my-ip-here>...
  * TCP_NODELAY set
  * Connected to my-company (my-ip-here) port 443 (#0)
  * ALPN, offering h2
  * ALPN, offering http/1.1
  * successfully set certificate verify locations:
  *   CAfile: /etc/ssl/certs/ca-certificates.crt
    CApath: /etc/ssl/certs
  * (304) (OUT), TLS handshake, Client hello (1):
  * (304) (IN), TLS handshake, Server hello (2):
  * TLSv1.2 (IN), TLS handshake, Certificate (11):
  * TLSv1.2 (IN), TLS handshake, Server key exchange (12):
  * TLSv1.2 (IN), TLS handshake, Server finished (14):
  * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
  * TLSv1.2 (OUT), TLS change cipher, Client hello (1):
  * TLSv1.2 (OUT), TLS handshake, Finished (20):
  * TLSv1.2 (IN), TLS handshake, Finished (20):
  * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
  * ALPN, server did not agree to a protocol
  * Server certificate:
  *  subject: CN=*.mycompany.com
  *  start date: Dec  4 00:00:00 2019 GMT
  *  expire date: Jan  4 12:00:00 2021 GMT
  *  subjectAltName: host "my-company" matched cert's "*.my-company"
  *  issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
  *  SSL certificate verify ok.
  > POST /graphql HTTP/1.1
  > Host: my-company
  > User-Agent: curl/7.58.0
  > Accept: */*
  > Content-Type: application/json
  > Content-Length: 159
  > 
  * upload completely sent off: 159 out of 159 bytes
  * TLSv1.2 (IN), TLS alert, Client hello (1):
  * Empty reply from server
  * Connection #0 to host my-company left intact
  curl: (52) Empty reply from server

标签: nginxgraphqlreverse-proxyapollo-server

解决方案


推荐阅读