curl请求https资源的时候出现400
在nginx上配置了一个新的域名, 习惯性地用curl请求看看有没有配置错误
因为是https的, 所以
$curl 'https://test.test.com/' -x 127.0.0.1:443 -i -L
HTTP/1.1 400 Bad Request
Server: nginx/1.9.12
Date: Mon, 08 Aug 2016 07:56:21 GMT
Content-Type: text/html
Content-Length: 173
Connection: close curl: (56) Received HTTP code 400 from proxy after CONNECT
400了..ToT
拿浏览器绑个hosts, 正常返回了... @.@
一定curl差了些什么参数了
看了下服务端上面的访问日志, 看到了形如以下的访问日志
[08/Aug/2016:16:07:27 +0800] "CONNECT test.test.com:443 HTTP/1.1" 400 173 "-" "-" "-"
果断先拿百度开刷
# curl 'https://www.baidu.com/' -i -L -v
* About to connect() to www.baidu.com port 443 (#0)
* Trying 14.215.177.38... connected
* Connected to www.baidu.com (14.215.177.38) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* SSL connection using TLS_RSA_WITH_AES_128_CBC_SHA
* Server certificate:
* <span style="white-space:pre"> </span>subject: CN=baidu.com,OU=service operation department,O="Beijing Baidu Netcom Science Technology Co., Ltd.",L=Beijing,ST=Beijing,C=CN
* <span style="white-space:pre"> </span>start date: Sep 17 00:00:00 2015 GMT
* <span style="white-space:pre"> </span>expire date: Aug 31 23:59:59 2016 GMT
* <span style="white-space:pre"> </span>common name: baidu.com
* <span style="white-space:pre"> </span>issuer: CN=VeriSign Class 3 International Server CA - G3,OU=Terms of use at https://www.verisign.com/rpa (c)10,OU=VeriSign Trust Network,O="VeriSign, Inc.",C=US
> GET / HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: www.baidu.com
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Server: bfe/1.0.8.14
Server: bfe/1.0.8.14
< Date: Mon, 08 Aug 2016 08:11:00 GMT
Date: Mon, 08 Aug 2016 08:11:00 GMT
< Content-Type: text/html
Content-Type: text/html
< Content-Length: 227
Content-Length: 227
< Connection: keep-alive
Connection: keep-alive
< Last-Modified: Thu, 09 Oct 2014 10:47:57 GMT
Last-Modified: Thu, 09 Oct 2014 10:47:57 GMT
< Set-Cookie: BD_NOT_HTTPS=1; path=/; Max-Age=300
Set-Cookie: BD_NOT_HTTPS=1; path=/; Max-Age=300
< Set-Cookie: BIDUPSID=4264F64D03A9A0D1FE68735BBB55FF4E; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Set-Cookie: BIDUPSID=4264F64D03A9A0D1FE68735BBB55FF4E; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
< Set-Cookie: PSTM=1470643860; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Set-Cookie: PSTM=1470643860; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
< P3P: CP=" OTI DSP COR IVA OUR IND COM "
P3P: CP=" OTI DSP COR IVA OUR IND COM "
< X-UA-Compatible: IE=Edge,chrome=1
X-UA-Compatible: IE=Edge,chrome=1
< Pragma: no-cache
Pragma: no-cache
< Cache-control: no-cache
Cache-control: no-cache
< Strict-Transport-Security: max-age=0
Strict-Transport-Security: max-age=0
< Accept-Ranges: bytes
Accept-Ranges: bytes
< Set-Cookie: __bsi=13639875133713009970_00_301_N_N_1_0301_002F_N_N_N_0; expires=Mon, 08-Aug-16 08:11:05 GMT; domain=www.baidu.com; path=/
Set-Cookie: __bsi=13639875133713009970_00_301_N_N_1_0301_002F_N_N_N_0; expires=Mon, 08-Aug-16 08:11:05 GMT; domain=www.baidu.com; path=/ <
<html>
<head>
<span style="white-space:pre"> </span><script>
<span style="white-space:pre"> </span>location.replace(location.href.replace("https://","http://"));
<span style="white-space:pre"> </span></script>
</head>
<body>
<span style="white-space:pre"> </span><noscript><meta http-equiv="refresh" content="0;url=http://www.baidu.com/"></noscript>
</body>
* Connection #0 to host www.baidu.com left intact
* Closing connection #0
</html>
</pre><pre name="code" class="plain">
# curl 'https://www.baidu.com/' -i -L -v -x '103.235.46.39:443' ###103.235..39是跑到 8.8.8.8 dns出来的ip
* About to connect() to proxy 103.235.46.39 port (#)
* Trying 103.235.46.39... connected
* Connected to 103.235.46.39 (103.235.46.39) port (#)
<pre name="code" class="plain">* Establish HTTP proxy tunnel to www.baidu.com:
> CONNECT www.baidu.com: HTTP/1.1
> Host: www.baidu.com:> User-Agent: curl/7.19. (x86_64-redhat-linux-gnu) libcurl/7.19. NSS/3.21 Basic ECC zlib/1.2. libidn/1.18 libssh2/1.4.> Proxy-Connection: Keep-Alive>< HTTP/1.1 Moved TemporarilyHTTP/1.1 Moved Temporarily< Server: bfe/1.0..14Server: bfe/1.0.8.14< Date: Mon, Aug :: GMTDate: Mon, Aug :: GMT< Content-Type: text/htmlContent-Type: text/html< Content-Length: 161Content-Length: < Connection: closeConnection: close< Location: https://www.baidu.com/search/error.htmlLocation: https://www.baidu.com/search/error.html<* Received HTTP code 302 from proxy after CONNECT* Closing connection #0curl: (56) Received HTTP code 302 from proxy after CONNECT
两次请求百度首页, 区别在于 -x 这个参数, 从而确定是这个参数惹的祸
其实会留意到有这么两行
* Establish HTTP proxy tunnel to www.baidu.com:
> CONNECT www.baidu.com: HTTP/1.1
curl -x参数, man文档里面对这个参数的描述, 第一句就是 'Use the specified proxy'
大致原因是因为 -x 参数的原因, curl 把 127.0.0.1:443 当成 http proxy 来用
对于 https 的请求, curl 对proxy 先发起一个 connect 请求
但, nginx没有实现 connect 方法
导致 客户端直接报错
解决方法, 目前只看到绕过过去的方法, 改下请求的方式咯
# 这个请求会报错, 会报证书出错
curl 'https://127.0.0.1/' -H 'Host:test.test.com' -i -L -v
# 加个 -k, 不验证证书, 请求成功
curl 'https://127.0.0.1/' -H 'Host:test.test.com' -i -L -v -k
参考:http://blog.csdn.net/tacuhuh/article/details/52152695
curl请求https资源的时候出现400的更多相关文章
- php-fpm nginx 使用 curl 请求 https 出现 502 错误
用php curl请求https的url出现502错误,请求帮忙解决. PHP版本:5.6.7Nginx版本:1.8.0 代码如下: $ch = curl_init(); curl_setopt($c ...
- PHP curl请求https遇到的坑
PHP里curl对https的证书配置默认是服务器端要求验证的,如果服务器端没有配置证书验证,则无法请求https路径.如果为了简便使用不需要配置https证书的话,配置curl时将以下两项设置为fa ...
- PHP使用curl请求https站点的常见错误及解决方案
使用curl请求http站点和https站点最大的不同就是https站点有证书验证这一环节,如果证书验证不通过则无法发起请求,不管是请求什么类型的站点遇到问题时先把错误码打印出来看一下,打印错误码的代 ...
- PHP使用file_get_contents或curl请求https的域名内容为空或Http 505错误的问题排查方法
前段日子,突然接到用户的反馈,说系统中原来的QQ登录.微博登录通通都不能用,跟踪代码进去后发现,是在 file_get_contents这个函数请求QQ登录的地方报错,在用该函数file_get_co ...
- PHP Curl请求Https接口
在请求http的时候只需要 file_get_contents("http://www.sojson.com/open/api/weather/json.shtml?city=$Positi ...
- cURL 学习笔记与总结(5)用 cURL 访问 HTTPS 资源
<?php $curlobj = curl_init(); // 初始化 curl_setopt($curlobj, CURLOPT_URL, "https://ajax.aspnet ...
- php curl请求https 返回无结果|false|errno:35
1 SSL: certificate subject name 'WMSvc-GWAMSERVER02' does not match target host name 把curl_setopt($c ...
- PHP Curl 请求https 60错误解决办法
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
- curl请求https请求
function curl_https($url,$data){ $ch = curl_init (); curl_setopt ( $ch, CURLOPT_URL, $url ); curl_se ...
随机推荐
- SAP翔子_增强篇索引
序号 描述 SAP翔子_增强篇0 增强篇0 SAP的多种增强方式 SAP翔子_增强篇1 增强篇1 PO保存增强 SAP翔子_增强篇2 增强篇2 生产订单屏幕增强 SAP翔子_增强篇3 增强篇3 SAP ...
- EasyNVR网页摄像机无插件H5、谷歌Chrome直播方案之使用ffmpeg保存快照数据方法与代码
背景分析 EasyNVR主要功能模块有设备发现与接入.实时直播.摄像机控制.录像与管理.设备快照与状态维护.第三方平台对接,其中设备快照与状态维护主要包括定时检测通道设备的在线状态.定时对通道摄像机进 ...
- vue脚手架中使用Vant,实现自动按需引入组件,并将px转换为rem
偶然间看到一款不错的移动端vue组件库Vant,照着官方文档敲了一下,感觉还是不错的.想着以后的项目中可能会运用到,特此记录下,方便之后使用. 现在很多的组件库为了减小代码包体积,都支持按需加载了.V ...
- python入门和杂识
1需要理解的一些概念 1.C语言编译完就是机器码,机器码可以直接在处理器上执行. 2.CPU可以直接读取机器码. 3.Python是用C写的. 4.Python解释器会把代码内容读到内存里,通过Pyt ...
- jq同一页面内容切换
$(function() { //选择标题显示 初始显示内容及样式 $('.right-content .right-item').eq(0).addClass('showcontent') $('. ...
- InvokeMember 使用(转http://blog.csdn.net/gooer/article/details/2927113)
函数原型: public object InvokeMember(string, BindingFlags, Binder, object, object[]); ...
- csu 1978: LXX的图论题
1978: LXX的图论题 Submit Page Summary Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 71 ...
- 如何理解JavaScript的原型和原型链
在现在的业务开发中,应该很少人在写原生JavaScript了,大家都一股脑地扑在各个框架上.本来,这些框架对于业务和开发者来说是一种福音,减少了各种各样的开发痛点,但是带来的负面问题就是对于开发者来说 ...
- js实现html表格<td>标签中带换行的文本显示出换行效果
遇见问题 如下内容中我写了几行,但是表格中并未按行显示,换行符反而变成了空格,于是想自己转换下 思考问题 1.可以看到表格的内容是后端传来的数据,于是想直接在后端转换下,把换行符替换成<br&g ...
- Docker容器数据管理(数据卷&数据卷容器)
一:前言 在Docker容器的实际使用中,经常会遇到容器的数据持久化,容器之间的数据共享等问题,通常我们有两种解决方案: 1)数据卷(Data Volumes):就是将容器内数据直接映射到本地主机环境 ...