【问题标题】:Why isn't curl working with my TLS ngrok tunnel?为什么 curl 不能与我的 TLS ngrok 隧道一起使用?
【发布时间】:2015-10-31 11:17:09
【问题描述】:

当我在通往基于 Apache IP 的虚拟主机的 TLS 隧道上运行 curl --insecure 'https://foo.ngrok.io/page' 时,我收到“400 Bad Request”响应,说“您的浏览器发送了此服务器无法理解的请求...原因:您'正在向启用 SSL 的服务器端口发送纯 HTTP...请改为使用 HTTPS 方案访问此 URL。”

但是,如果我使用 curl 直接向我的本地主机地址发出请求,例如curl --insecure 'https://foo/page'我得到了正确的回应。另外,如果我在浏览器中向https://foo.ngrok.io/page 发出请求,我会得到正确的响应。

我正在运行:OS X 10.9.5、Apache 2.4、ngrok2 和 curl 7.43.0。我的 SSL 证书是自签名的。

我从访问日志中注意到,当我在 foo.ngrok.io 上使用 curl 时,我的 HTTP/1.1 请求更改为 HTTP/1.0 请求。另外,这是我的错误日志中相应的相关位:

ssl_engine_kernel.c(1824): [client 127.0.0.2:50517] OpenSSL: Exit: error in SSLv2/v3 read client hello A
[client 127.0.0.2:50517] AH01996: SSL handshake failed: HTTP spoken on HTTPS port; trying to send HTML error page
SSL Library Error: error:1407609C:SSL routines:SSL23_GET_CLIENT_HELLO:http request -- speaking HTTP to HTTPS port!?
protocol.c(616): [client 127.0.0.2:50517] Request received from client: GET / HTTP/1.0
http_filters.c(1042): [client 127.0.0.2:50517] Response sent with status 400, headers:

Apache 虚拟主机配置

Listen 127.0.0.2:443
<VirtualHost 127.0.0.2:443>
        ServerName foo
        DocumentRoot /Users/me/site
        ErrorLog "/usr/local/var/log/apache2/foo_error_log"
        CustomLog "/usr/local/var/log/apache2/foo_access_log" common
        <Directory "/Users/me/site">
                AllowOverride All
                Allow from All
                Options -Indexes
        </Directory>
        <IfModule ssl_module>
                SSLEngine on
                <Directory "/Users/me/site">
                        SSLOptions +StdEnvVars
                </Directory>
                SSLCertificateKeyFile "/usr/local/etc/apache2/2.4/ssl/foo.key"
                SSLCertificateFile "/usr/local/etc/apache2/2.4/ssl/foo.crt"
        </IfModule>
</VirtualHost>

Apache SSL 配置

SSLRandomSeed startup file:/dev/urandom 512
SSLRandomSeed connect file:/dev/urandom 512
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLPassPhraseDialog  builtin
SSLSessionCache "shmcb:/usr/local/var/run/apache2/ssl_scache(512000)"
SSLSessionCacheTimeout 300

ngrok.yml 配置

authtoken: <omitted>
tunnels:
  foo:
    addr: 127.0.0.2:443
    proto: tls
    hostname: "foo.ngrok.io"

【问题讨论】:

  • 注意:真正的问题不是我不能使用 curl,而是我使用 ngrok 来制作 webhook 的服务也有同样的问题。

标签: apache ssl curl ngrok


【解决方案1】:

目前,HTTP 客户端(curl、浏览器等)必须支持 SNI 才能通过 HTTPS 与 ngrok 通信。这涉及 TLS 和 HTTP ngrok 隧道。

【讨论】:

    【解决方案2】:

    尝试在 curl 命令后添加 -k。例如:

    curl https://www{domain}com.ngrok.io/webhook -k

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-04
      • 1970-01-01
      • 2021-11-12
      • 2017-09-21
      • 2011-12-25
      • 2020-10-08
      • 2023-03-24
      • 1970-01-01
      相关资源
      最近更新 更多