当我在我的基于 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"
最佳答案
目前,HTTP 客户端(curl、浏览器等)必须支持 SNI 才能通过 HTTPS 与 ngrok 通信。这涉及 TLS 和 HTTP ngrok 隧道。
关于apache - 为什么 curl 不能与我的 TLS ngrok 隧道一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31887416/