带 ssl 的 http 服务器不适用于 nc

带 ssl 的 http 服务器不适用于 nc

如果运行:

cat index.html  | nc --ssl --broker --keep-open   -l 443

在客户端浏览器继续尝试连接但没有成功。我的意思是,html 页面无法加载。

此外,curl 输出为:

curl -v  -k https://10.0.3.226/index.html
*   Trying 10.0.3.226:443...
* TCP_NODELAY set
* Connected to 10.0.3.226 (10.0.3.226) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (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, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=localhost
*  start date: Oct 30 13:06:20 2019 GMT
*  expire date: Oct 29 13:06:20 2020 GMT
*  issuer: CN=localhost
*  SSL certificate verify result: self signed certificate (18), continuing anyway.
> GET /index.html HTTP/1.1
> Host: 10.0.3.226
> User-Agent: curl/7.65.3
> Accept: */*
> 

有办法让它发挥作用吗?

PS:nc 是 nmap 包中的 ncat。

答案1

HTTP/1 响应需要 HTTP 标头(状态代码、元数据)和 HTTP 正文(即内容)。您的index.html可能只是内容。如果这是一个可接受的响应,取决于您的客户端是否支持 20 多年已过时的 HTTP/0.9 协议(不发送标头)。很多人没有。

相关内容