![URL 在 wget 中有效,但在 curl 中无效(与 apt 相关)](https://linux22.com/image/894900/URL%20%E5%9C%A8%20wget%20%E4%B8%AD%E6%9C%89%E6%95%88%EF%BC%8C%E4%BD%86%E5%9C%A8%20curl%20%E4%B8%AD%E6%97%A0%E6%95%88%EF%BC%88%E4%B8%8E%20apt%20%E7%9B%B8%E5%85%B3%EF%BC%89.png)
这是一个让我摸不着头脑的奇怪情况。首先,我在运行 时发现了这个错误sudo apt-get update
,并收到
Err https://packagecloud.io jessie/main amd64 Packages
Failed to connect to packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com port 443: Network is unreachable
Err https://packagecloud.io jessie/main i386 Packages
Failed to connect to packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com port 443: Network is unreachable
Hit http://ppa.launchpad.net trusty/main i386 Packages
[...snipped...]
W: Failed to fetch https://packagecloud.io/slacktechnologies/slack/debian/dists/jessie/main/binary-amd64/Packages Failed to connect to packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com port 443: Network is unreachable
W: Failed to fetch https://packagecloud.io/slacktechnologies/slack/debian/dists/jessie/main/binary-i386/Packages Failed to connect to packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com port 443: Network is unreachable
E: Some index files failed to download. They have been ignored, or old ones used instead.
注意:我使用的是 Ubuntu 14.04 Trusty,但我已将其设置为从 Debian Jessie repo 下载 slack。这不是问题。
按照此 URL(即https://packagecloud.io/slacktechnologies/slack/debian/dists/jessie/main/binary-i386/Packages) 在浏览器中显示它完全可以浏览。因此我想检查我的 是否有问题apt
。因此,我使用了curl
和wget
,得到了不同的结果:
为了curl
:
$ curl -v https://packagecloud.io/slacktechnologies/slack/debian/dists/jessie/main/binary-i386/Packages
* Hostname was NOT found in DNS cache
* Trying 50.97.198.58...
* Trying 2607:f0d0:2101:270::2...
* connect to 2607:f0d0:2101:270::2 port 443 failed: Network is unreachable
* Failed to connect to packagecloud.io port 443: Network is unreachable
* Closing connection 0
curl: (7) Failed to connect to packagecloud.io port 443: Network is unreachable
为了wget
:
wget -d https://packagecloud.io/slacktechnologies/slack/debian/dists/jessie/main/binary-i386/Packages
DEBUG output created by Wget 1.15 on linux-gnu.
URI encoding = ‘UTF-8’
--2017-07-21 18:11:10-- https://packagecloud.io/slacktechnologies/slack/debian/dists/jessie/main/binary-i386/Packages
Resolving packagecloud.io (packagecloud.io)... 50.97.198.58, 2607:f0d0:2101:270::2
Caching packagecloud.io => 50.97.198.58 2607:f0d0:2101:270::2
Connecting to packagecloud.io (packagecloud.io)|50.97.198.58|:443... connected.
Created socket 3.
Releasing 0x00000000018412b0 (new refcount 1).
Initiating SSL handshake.
Handshake successful; connected socket 3 to SSL handle 0x00000000018415e0
certificate:
subject: /OU=Domain Control Validated/OU=EssentialSSL/CN=packagecloud.io
issuer: /C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Domain Validation Secure Server CA
X509 certificate successfully verified and matches host packagecloud.io
---request begin---
GET /slacktechnologies/slack/debian/dists/jessie/main/binary-i386/Packages HTTP/1.1
User-Agent: Wget/1.15 (linux-gnu)
Accept: */*
Host: packagecloud.io
Connection: Keep-Alive
---request end---
HTTP request sent, awaiting response...
---response begin---
HTTP/1.1 302 Found
Server: nginx
Date: Fri, 21 Jul 2017 12:41:17 GMT
Content-Type: text/html;charset=utf-8
Content-Length: 0
Connection: keep-alive
Status: 302 Found
Strict-Transport-Security: max-age=31536000
Location: https://packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com/925/1150/debian/dists/jessie/main/binary-i386/Packages?AWSAccessKeyId=AKIAI44QGWC7C5WEV4XA&Signature=Vltn5Ghi49icZIN7Ho5DphMEbRE%3D&Expires=1500641185
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Cache-Control: no-cache
X-Request-Id: 571637cb-6a78-47b1-8558-45a67c428064
X-Runtime: 0.018935
---response end---
302 Found
Registered socket 3 for persistent reuse.
URI content encoding = ‘utf-8’
Location: https://packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com/925/1150/debian/dists/jessie/main/binary-i386/Packages?AWSAccessKeyId=AKIAI44QGWC7C5WEV4XA&Signature=Vltn5Ghi49icZIN7Ho5DphMEbRE%3D&Expires=1500641185 [following]
] done.
URI content encoding = None
--2017-07-21 18:11:11-- https://packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com/925/1150/debian/dists/jessie/main/binary-i386/Packages?AWSAccessKeyId=AKIAI44QGWC7C5WEV4XA&Signature=Vltn5Ghi49icZIN7Ho5DphMEbRE%3D&Expires=1500641185
Resolving packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com (packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com)... 52.219.20.25, 2600:1fa0:c040:80:36e7:ec1c::
Caching packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com => 52.219.20.25 2600:1fa0:c040:80:36e7:ec1c::
Connecting to packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com (packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com)|52.219.20.25|:443... connected.
Created socket 4.
Releasing 0x000000000185a150 (new refcount 1).
Initiating SSL handshake.
Handshake successful; connected socket 4 to SSL handle 0x0000000001860bc0
certificate:
subject: /C=US/ST=Washington/L=Seattle/O=Amazon.com Inc./CN=*.s3-us-west-1.amazonaws.com
issuer: /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert Baltimore CA-2 G2
X509 certificate successfully verified and matches host packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com
---request begin---
GET /925/1150/debian/dists/jessie/main/binary-i386/Packages?AWSAccessKeyId=AKIAI44QGWC7C5WEV4XA&Signature=Vltn5Ghi49icZIN7Ho5DphMEbRE%3D&Expires=1500641185 HTTP/1.1
User-Agent: Wget/1.15 (linux-gnu)
Accept: */*
Host: packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com
Connection: Keep-Alive
---request end---
HTTP request sent, awaiting response...
---response begin---
HTTP/1.1 200 OK
x-amz-id-2: cDzrsyunzEU7POUHrPqzqAV+oPLWkeRrMPgDQeKATtgenMpv2EUbCQjy+88AKQ6rp8FTO2shkv0=
x-amz-request-id: 76F0FF5E248DAFDE
Date: Fri, 21 Jul 2017 12:41:19 GMT
Last-Modified: Thu, 08 Jun 2017 00:13:11 GMT
ETag: "857ccd845e08a3963199ffbb587a0f4f"
Cache-Control: max-age=31536000
Accept-Ranges: bytes
Content-Type: text/plain
Content-Length: 20053
Server: AmazonS3
---response end---
200 OK
Disabling further reuse of socket 3.
Closed 3/SSL 0x00000000018415e0
Registered socket 4 for persistent reuse.
Length: 20053 (20K) [text/plain]
Saving to: ‘Packages’
100%[====================================================================================================================================================================>] 20,053 46.6KB/s in 0.4s
2017-07-21 18:11:12 (46.6 KB/s) - ‘Packages’ saved [20053/20053]
基本上,URL 似乎可以通过wget
和浏览器工作,但不能通过apt-get
或工作curl
。
我没有安装任何代理,最近也没有调整任何与网络相关的配置。但是,这个问题在过去一个月多的时间里突然出现,我很想听听我可以尝试调试/修复这个问题的方法。
答案1
注意 HTTP 302 状态代码。这是一个重定向,意味着提供的 URL 映射到另一个 URL。默认情况下,Wget 遵循重定向,而 curl 不遵循。浏览器通常也默认遵循重定向。为了让 curl 遵循重定向,请使用选项-L or --location
。
引用手册页,
-L,--location
(HTTP)如果服务器报告请求的页面已移动到其他位置(用 Location:标头和 3XX 响应代码表示),此选项将使 curl 在新位置重新执行请求。
不幸的是,我无法帮助解决 apt-get 部分的问题,因为我不是 Ubuntu 专家。
我刚刚想到,你能不能将更新站点的位置改为
packagecloud-repositories.s3.dualstack.us-west-1.amazonaws.com/925/1150/debian/dists/jessie/main/binary-i386/Packages?AWSAccessKeyId=AKIAI44QGWC7C5WEV4XA&Signature=Vltn5Ghi49icZIN7Ho5DphMEbRE%3D&Expires=1500641185
代替
packagecloud.io/slacktechnologies/slack/debian/dists/jessie/main/binary-i386/Packages
?
希望这可以帮助!