最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Nginx Connections aren't reused in MacOS - Stack Overflow

programmeradmin3浏览0评论

I have setup nginx server to serve a static html file and want the connection to be reused everytime I call the server.

http{
  keepalive_timeout 60s;
  keepalive_requests 1000;
  server {
    listen 8080 ssl;
    http2 on;
    location / {
      root html;
      index index.html index.htm;
    }
    ssl_certificate path/self-signed.crt;
    ssl_certificate_key path/self-signed.key;
  }
}

But when I call from browser or via curl, the connection is left intact but not reused

➜  ssl git:(stable) curl -v --http2 --no-keepalive https://localhost:8080/

* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8080...
* connect to ::1 port 8080 from ::1 port 57735 failed: Connection refused
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080
* ALPN: curl offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* (304) (IN), TLS handshake, Server hello (2):
* (304) (IN), TLS handshake, Unknown (8):
* (304) (IN), TLS handshake, Certificate (11):
* (304) (IN), TLS handshake, CERT verify (15):
* (304) (IN), TLS handshake, Finished (20):
* (304) (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256 / [blank] / UNDEF
* ALPN: server accepted h2
* Server certificate:
*  subject: CN=localhost
*  start date: Feb 16 17:32:14 2025 GMT
*  expire date: Feb 16 17:32:14 2026 GMT
*  subjectAltName: host "localhost" matched cert's "localhost"
*  issuer: CN=localhost
*  SSL certificate verify ok.
* using HTTP/2
* [HTTP/2] [1] OPENED stream for https://localhost:8080/
* [HTTP/2] [1] [:method: GET]
* [HTTP/2] [1] [:scheme: https]
* [HTTP/2] [1] [:authority: localhost:8080]
* [HTTP/2] [1] [:path: /]
* [HTTP/2] [1] [user-agent: curl/8.7.1]
* [HTTP/2] [1] [accept: */*]
> GET / HTTP/2
> Host: localhost:8080
> User-Agent: curl/8.7.1
> Accept: */*
>
* Request completely sent off
< HTTP/2 200
< server: nginx/1.27.4
< date: Sun, 16 Feb 2025 20:39:15 GMT
< content-type: text/html
< content-length: 44
< last-modified: Thu, 13 Feb 2025 08:40:04 GMT
< etag: "67adafe4-2c"
< accept-ranges: bytes
<
<html><body><h1>It Temp!</h1></body></html>
* Connection #0 to host localhost left intact
➜  ssl git:(stable) curl -v --http2 --no-keepalive https://localhost:8080/

* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8080...
* connect to ::1 port 8080 from ::1 port 57737 failed: Connection refused
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080
* ALPN: curl offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* (304) (IN), TLS handshake, Server hello (2):
* (304) (IN), TLS handshake, Unknown (8):
* (304) (IN), TLS handshake, Certificate (11):
* (304) (IN), TLS handshake, CERT verify (15):
* (304) (IN), TLS handshake, Finished (20):
* (304) (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256 / [blank] / UNDEF
* ALPN: server accepted h2
* Server certificate:
*  subject: CN=localhost
*  start date: Feb 16 17:32:14 2025 GMT
*  expire date: Feb 16 17:32:14 2026 GMT
*  subjectAltName: host "localhost" matched cert's "localhost"
*  issuer: CN=localhost
*  SSL certificate verify ok.
* using HTTP/2
* [HTTP/2] [1] OPENED stream for https://localhost:8080/
* [HTTP/2] [1] [:method: GET]
* [HTTP/2] [1] [:scheme: https]
* [HTTP/2] [1] [:authority: localhost:8080]
* [HTTP/2] [1] [:path: /]
* [HTTP/2] [1] [user-agent: curl/8.7.1]
* [HTTP/2] [1] [accept: */*]
> GET / HTTP/2
> Host: localhost:8080
> User-Agent: curl/8.7.1
> Accept: */*
>
* Request completely sent off
< HTTP/2 200
< server: nginx/1.27.4
< date: Sun, 16 Feb 2025 20:39:15 GMT
< content-type: text/html
< content-length: 44
< last-modified: Thu, 13 Feb 2025 08:40:04 GMT
< etag: "67adafe4-2c"
< accept-ranges: bytes
<
<html><body><h1>It Temp!</h1></body></html>
* Connection #0 to host localhost left intact

This is the os sysctl

net.inet.tcp.keepidle: 7200000
net.inet.tcp.keepintvl: 75000
net.inet.tcp.keepinit: 75000
net.inet.tcp.keepcnt: 8
net.inet.tcp.always_keepalive: 1
net.inet.mptcp.keepalive: 840
net.link.ether.inet.keep_announcements: 1
net.key.natt_keepalive_interval: 20
net.inet6.ip6.keepfaith: 0
net.necp.pass_keepalives: 1
security.mac.asp.policy.gatekeeper_enabled: 1

I have also tried to check if the problem was due to loopback interface but using ip also didn't help. Can someone help narrow down the issue?

发布评论

评论列表(0)

  1. 暂无评论