curl https://domasin报错 NSS error -12286

本文详细记录了在华南灰度环境和华南VPC中使用curl进行HTTPS请求时遇到的错误,发现该错误与nss版本过低无法加载新证书有关。通过对比不同环境的nss版本,确认了问题原因,并成功通过更新nss版本解决了问题。
对于上面的问题怀疑是和nss版本有关,以下将分别在华南vpc和华南灰度机验证curl请求

一、在华南灰度环境测试
1、curl s3内网新域名(报错)
[root@A06-R12-302F0714-I12-86 --PROD-- ~]# curl -I https://s3-internal.cn-south-1.jdcloud-oss.com/a/a -v
* About to connect() to s3-internal.cn-south-1.jdcloud-oss.com port 443 (#0)
*   Trying 100.65.254.35...
* Connected to s3-internal.cn-south-1.jdcloud-oss.com (100.65.254.35) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* NSS error -12286 (SSL_ERROR_NO_CYPHER_OVERLAP)
* Cannot communicate securely with peer: no common encryption algorithm(s).
* Error in TLS handshake, trying SSLv3...
> HEAD /a/a HTTP/1.1
> User-Agent: curl/7.29.0
> Host: s3-internal.cn-south-1.jdcloud-oss.com
> Accept: */*
> 
* Connection died, retrying a fresh connect
* Closing connection 0
* Issue another request to this URL: 'https://s3-internal.cn-south-1.jdcloud-oss.com/a/a'
* About to connect() to s3-internal.cn-south-1.jdcloud-oss.com port 443 (#1)
*   Trying 100.65.254.35...
* Connected to s3-internal.cn-south-1.jdcloud-oss.com (100.65.254.35) port 443 (#1)
* TLS disabled due to previous handshake failure
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* NSS error -12286 (SSL_ERROR_NO_CYPHER_OVERLAP)
* Cannot communicate securely with peer: no common encryption algorithm(s).
* Closing connection 1
curl: (35) Cannot communicate securely with peer: no common encryption algorithm(s).
2、测试443端口是否开放(全部ok)
[root@A06-R12-302F0714-I12-86 --PROD-- ~]# telnet 127.0.0.1 443
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
^CConnection closed by foreign host.
[root@A06-R12-302F0714-I12-86 --PROD-- ~]# telnet 100.65.254.3 443
Trying 100.65.254.3...
Connected to 100.65.254.3.
Escape character is '^]'.
3、curl s3外网新域名 (结果ok)
[root@A06-R12-302F0714-I12-86 --PROD-- ~]# curl -I https://s3.cn-south-1.jdcloud-oss.com/a/a -v
* About to connect() to s3.cn-south-1.jdcloud-oss.com port 443 (#0)
*   Trying 59.37.144.139...
* Connected to s3.cn-south-1.jdcloud-oss.com (59.37.144.139) 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:
* 	subject: CN=*.s3.cn-north-1.jdcloud-oss.com,O="BEIJING JINGDONG SHANGKE INFORMATION TECHNOLOGY CO., LTD.",L=beijing,ST=beijing,C=CN
* 	start date: Jan 29 09:31:09 2019 GMT
* 	expire date: Jan 30 09:31:09 2020 GMT
* 	common name: *.s3.cn-north-1.jdcloud-oss.com
* 	issuer: CN=GlobalSign Organization Validation CA - SHA256 - G2,O=GlobalSign nv-sa,C=BE
> HEAD /a/a HTTP/1.1
> User-Agent: curl/7.29.0
> Host: s3.cn-south-1.jdcloud-oss.com
> Accept: */*
> 
< HTTP/1.1 404 Not Found
HTTP/1.1 404 Not Found
< Server: jfe
Server: jfe
< Date: Mon, 11 Mar 2019 04:53:31 GMT
Date: Mon, 11 Mar 2019 04:53:31 GMT
< Content-Length: 0
Content-Length: 0
< Connection: keep-alive
Connection: keep-alive
< x-req-id: B6E24BAF242EF989
x-req-id: B6E24BAF242EF989

< 
* Connection #0 to host s3.cn-south-1.jdcloud-oss.com left intact
4、curl s3老域名(结果OK)
[root@A06-R12-302F0714-I12-86 --PROD-- ~]# curl -I https://s3.cn-south-1.jcloudcs.com/a/a -v
* About to connect() to s3.cn-south-1.jcloudcs.com port 443 (#0)
*   Trying 100.65.11.130...
* Connected to s3.cn-south-1.jcloudcs.com (100.65.11.130) 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:
* 	subject: CN=*.jdcloud.com,O="BEIJING JINGDONG SHANGKE INFORMATION TECHNOLOGY CO., LTD.",L=beijing,ST=beijing,C=CN
* 	start date: Nov 19 02:26:04 2018 GMT
* 	expire date: Feb 18 09:06:02 2020 GMT
* 	common name: *.jdcloud.com
* 	issuer: CN=GlobalSign Organization Validation CA - SHA256 - G2,O=GlobalSign nv-sa,C=BE
> HEAD /a/a HTTP/1.1
> User-Agent: curl/7.29.0
> Host: s3.cn-south-1.jcloudcs.com
> Accept: */*
> 
< HTTP/1.1 404 Not Found
HTTP/1.1 404 Not Found
< Server: JDCloudOSS
Server: JDCloudOSS
< Date: Mon, 11 Mar 2019 04:53:46 GMT
Date: Mon, 11 Mar 2019 04:53:46 GMT
< Content-Length: 0
Content-Length: 0
< Connection: close
Connection: close
< x-req-id: 8228B04708806DDF
x-req-id: 8228B04708806DDF

< 
* Closing connection 0

二、华南vpc中测试
1、curl s3内网新域名(ok),测试其它域名也ok这里就不全贴了
[root@domain-cn-south-1 ~]# curl -I https://s3-internal.cn-south-1.jdcloud-oss.com/a/a -v
* About to connect() to s3-internal.cn-south-1.jdcloud-oss.com port 443 (#0)
*   Trying 100.65.254.35...
* Connected to s3-internal.cn-south-1.jdcloud-oss.com (100.65.254.35) 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_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate:
*   subject: CN=*.s3.cn-north-1.jdcloud-oss.com,O="BEIJING JINGDONG SHANGKE INFORMATION TECHNOLOGY CO., LTD.",L=beijing,ST=beijing,C=CN
*   start date: Jan 29 09:31:09 2019 GMT
*   expire date: Jan 30 09:31:09 2020 GMT
*   common name: *.s3.cn-north-1.jdcloud-oss.com
*   issuer: CN=GlobalSign Organization Validation CA - SHA256 - G2,O=GlobalSign nv-sa,C=BE
> HEAD /a/a HTTP/1.1
> User-Agent: curl/7.29.0
> Host: s3-internal.cn-south-1.jdcloud-oss.com
> Accept: */*
> 
< HTTP/1.1 404 Not Found
HTTP/1.1 404 Not Found
< Server: JDCloudOSS
Server: JDCloudOSS
< Date: Mon, 11 Mar 2019 05:13:33 GMT
Date: Mon, 11 Mar 2019 05:13:33 GMT
< Content-Length: 0
Content-Length: 0
< Connection: keep-alive
Connection: keep-alive
< x-req-id: 828EF8FED8952127
x-req-id: 828EF8FED8952127

< 
* Connection #0 to host s3-internal.cn-south-1.jdcloud-oss.com left intact

三、通过以上测试怀疑是nss版本问题导致无法加载新的证书
1、检查nss版本(华南灰度机nss版本低)

华南灰度机

[root@A06-R12-302F0714-I12-86 --PROD-- ~]# curl -V
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.15.4 zlib/1.2.7 libidn/1.28 libssh2/1.4.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp 
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz 
[root@A06-R12-302F0714-I12-86 --PROD-- ~]# rpm -qa | grep nss
openssh-server-6.6.1p1-11.el7.x86_64
nss-softokn-freebl-3.16.2.3-9.el7.x86_64
nss-util-3.16.2.3-2.el7.x86_64
openssl-1.0.1e-42.el7.x86_64
openssh-clients-6.6.1p1-11.el7.x86_64
nss-tools-3.16.2.3-5.el7.x86_64
nss-3.16.2.3-5.el7.x86_64
nss-sysinit-3.16.2.3-5.el7.x86_64
jansson-2.4-6.el7.x86_64
openssh-6.6.1p1-11.el7.x86_64
nss-softokn-3.16.2.3-9.el7.x86_64
libsss_nss_idmap-1.12.2-58.el7.x86_64
openssl-devel-1.0.1e-42.el7.x86_64
openssl-libs-1.0.1e-42.el7.x86_64

华南vpc

[root@domain-cn-south-1 ~]# curl -V
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.34 zlib/1.2.7 libidn/1.28 libssh2/1.4.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp 
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets 
[root@domain-cn-south-1 ~]# rpm -qa | grep nss
nss-3.36.0-5.el7_5.x86_64
jansson-2.10-1.el7.x86_64
nss-util-3.36.0-1.el7_5.x86_64
nss-pem-1.0.3-4.el7.x86_64
openssl-1.0.2k-12.el7.x86_64
nss-sysinit-3.36.0-5.el7_5.x86_64
nss-tools-3.36.0-5.el7_5.x86_64
openssh-clients-7.4p1-16.el7.x86_64
nss-softokn-freebl-3.36.0-5.el7_5.x86_64
nss-softokn-3.36.0-5.el7_5.x86_64
openssl-libs-1.0.2k-12.el7.x86_64
openssh-7.4p1-16.el7.x86_64
libsss_nss_idmap-1.16.0-19.el7_5.5.x86_64
openssh-server-7.4p1-16.el7.x86_64
四、更新华南灰度机nss版本
1、
[root@A06-R12-302F0714-I12-86 --PROD-- ~]# yum update nss
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base                                                                                                                                                                  | 3.6 kB  00:00:00     
extras                                                                                                                                                                | 3.4 kB  00:00:00     
updates                                                                                                                                                               | 3.4 kB  00:00:00     
(1/2): extras/7/x86_64/primary_db                                                                                                                                     | 180 kB  00:00:00     
(2/2): updates/7/x86_64/primary_db                                                                                                                                    | 2.5 MB  00:00:00     
Determining fastest mirrors
Resolving Dependencies
--> Running transaction check
---> Package nss.x86_64 0:3.16.2.3-5.el7 will be updated
--> Processing Dependency: nss = 3.16.2.3-5.el7 for package: nss-sysinit-3.16.2.3-5.el7.x86_64
--> Processing Dependency: nss(x86-64) = 3.16.2.3-5.el7 for package: nss-tools-3.16.2.3-5.el7.x86_64
---> Package nss.x86_64 0:3.36.0-7.1.el7_6 will be an update
--> Processing Dependency: nss-util >= 3.36.0-1.1 for package: nss-3.36.0-7.1.el7_6.x86_64
--> Processing Dependency: nss-softokn(x86-64) >= 3.36.0-1 for package: nss-3.36.0-7.1.el7_6.x86_64
--> Processing Dependency: nspr >= 4.19.0 for package: nss-3.36.0-7.1.el7_6.x86_64
--> Processing Dependency: nss-pem(x86-64) for package: nss-3.36.0-7.1.el7_6.x86_64
--> Processing Dependency: libnssutil3.so(NSSUTIL_3.31)(64bit) for package: nss-3.36.0-7.1.el7_6.x86_64
--> Processing Dependency: libnssutil3.so(NSSUTIL_3.24)(64bit) for package: nss-3.36.0-7.1.el7_6.x86_64
--> Processing Dependency: libnssutil3.so(NSSUTIL_3.21)(64bit) for package: nss-3.36.0-7.1.el7_6.x86_64
--> Running transaction check
---> Package nspr.x86_64 0:4.10.6-3.el7 will be updated
---> Package nspr.x86_64 0:4.19.0-1.el7_5 will be an update
---> Package nss-pem.x86_64 0:1.0.3-5.el7 will be installed
---> Package nss-softokn.x86_64 0:3.16.2.3-9.el7 will be updated
---> Package nss-softokn.x86_64 0:3.36.0-5.el7_5 will be an update
--> Processing Dependency: nss-softokn-freebl(x86-64) >= 3.36.0-5.el7_5 for package: nss-softokn-3.36.0-5.el7_5.x86_64
---> Package nss-sysinit.x86_64 0:3.16.2.3-5.el7 will be updated
---> Package nss-sysinit.x86_64 0:3.36.0-7.1.el7_6 will be an update
---> Package nss-tools.x86_64 0:3.16.2.3-5.el7 will be updated
---> Package nss-tools.x86_64 0:3.36.0-7.1.el7_6 will be an update
---> Package nss-util.x86_64 0:3.16.2.3-2.el7 will be updated
---> Package nss-util.x86_64 0:3.36.0-1.1.el7_6 will be an update
--> Running transaction check
---> Package nss-softokn-freebl.x86_64 0:3.16.2.3-9.el7 will be updated
---> Package nss-softokn-freebl.x86_64 0:3.36.0-5.el7_5 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================
 Package                                            Arch                                   Version                                             Repository                               Size
=============================================================================================================================================================================================
Updating:
 nss                                                x86_64                                 3.36.0-7.1.el7_6                                    updates                                 835 k
Installing for dependencies:
 nss-pem                                            x86_64                                 1.0.3-5.el7                                         base                                     74 k
Updating for dependencies:
 nspr                                               x86_64                                 4.19.0-1.el7_5                                      base                                    127 k
 nss-softokn                                        x86_64                                 3.36.0-5.el7_5                                      base                                    315 k
 nss-softokn-freebl                                 x86_64                                 3.36.0-5.el7_5                                      base                                    222 k
 nss-sysinit                                        x86_64                                 3.36.0-7.1.el7_6                                    updates                                  62 k
 nss-tools                                          x86_64                                 3.36.0-7.1.el7_6                                    updates                                 515 k
 nss-util                                           x86_64                                 3.36.0-1.1.el7_6                                    updates                                  78 k

Transaction Summary
=============================================================================================================================================================================================
Install             ( 1 Dependent package)
Upgrade  1 Package  (+6 Dependent packages)

Total download size: 2.2 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/8): nspr-4.19.0-1.el7_5.x86_64.rpm                                                                                                                                 | 127 kB  00:00:00     
(2/8): nss-pem-1.0.3-5.el7.x86_64.rpm                                                                                                                                 |  74 kB  00:00:00     
(3/8): nss-softokn-freebl-3.36.0-5.el7_5.x86_64.rpm                                                                                                                   | 222 kB  00:00:00     
(4/8): nss-softokn-3.36.0-5.el7_5.x86_64.rpm                                                                                                                          | 315 kB  00:00:00     
(5/8): nss-3.36.0-7.1.el7_6.x86_64.rpm                                                                                                                                | 835 kB  00:00:00     
(6/8): nss-tools-3.36.0-7.1.el7_6.x86_64.rpm                                                                                                                          | 515 kB  00:00:00     
(7/8): nss-sysinit-3.36.0-7.1.el7_6.x86_64.rpm                                                                                                                        |  62 kB  00:00:00     
(8/8): nss-util-3.36.0-1.1.el7_6.x86_64.rpm                                                                                                                           |  78 kB  00:00:00     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                        4.6 MB/s | 2.2 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : nspr-4.19.0-1.el7_5.x86_64                                                                                                                                               1/15 
/sbin/ldconfig: /usr/local/lib/libpcreposix.so.0 is not a symbolic link

  Updating   : nss-util-3.36.0-1.1.el7_6.x86_64                                                                                                                                         2/15 
/sbin/ldconfig: /usr/local/lib/libpcreposix.so.0 is not a symbolic link

  Updating   : nss-softokn-freebl-3.36.0-5.el7_5.x86_64                                                                                                                                 3/15 
  Updating   : nss-softokn-3.36.0-5.el7_5.x86_64                                                                                                                                        4/15 
/sbin/ldconfig: /usr/local/lib/libpcreposix.so.0 is not a symbolic link

  Installing : nss-pem-1.0.3-5.el7.x86_64                                                                                                                                               5/15 
  Updating   : nss-sysinit-3.36.0-7.1.el7_6.x86_64                                                                                                                                      6/15 
  Updating   : nss-3.36.0-7.1.el7_6.x86_64                                                                                                                                              7/15 
/sbin/ldconfig: /usr/local/lib/libpcreposix.so.0 is not a symbolic link

  Updating   : nss-tools-3.36.0-7.1.el7_6.x86_64                                                                                                                                        8/15 
  Cleanup    : nss-tools-3.16.2.3-5.el7.x86_64                                                                                                                                          9/15 
  Cleanup    : nss-sysinit-3.16.2.3-5.el7.x86_64                                                                                                                                       10/15 
  Cleanup    : nss-3.16.2.3-5.el7.x86_64                                                                                                                                               11/15 
/sbin/ldconfig: /usr/local/lib/libpcreposix.so.0 is not a symbolic link

  Cleanup    : nss-softokn-3.16.2.3-9.el7.x86_64                                                                                                                                       12/15 
/sbin/ldconfig: /usr/local/lib/libpcreposix.so.0 is not a symbolic link

  Cleanup    : nss-util-3.16.2.3-2.el7.x86_64                                                                                                                                          13/15 
/sbin/ldconfig: /usr/local/lib/libpcreposix.so.0 is not a symbolic link

  Cleanup    : nspr-4.10.6-3.el7.x86_64                                                                                                                                                14/15 
/sbin/ldconfig: /usr/local/lib/libpcreposix.so.0 is not a symbolic link

  Cleanup    : nss-softokn-freebl-3.16.2.3-9.el7.x86_64                                                                                                                                15/15 
  Verifying  : nss-3.36.0-7.1.el7_6.x86_64                                                                                                                                              1/15 
  Verifying  : nss-pem-1.0.3-5.el7.x86_64                                                                                                                                               2/15 
  Verifying  : nss-tools-3.36.0-7.1.el7_6.x86_64                                                                                                                                        3/15 
  Verifying  : nspr-4.19.0-1.el7_5.x86_64                                                                                                                                               4/15 
  Verifying  : nss-sysinit-3.36.0-7.1.el7_6.x86_64                                                                                                                                      5/15 
  Verifying  : nss-softokn-freebl-3.36.0-5.el7_5.x86_64                                                                                                                                 6/15 
  Verifying  : nss-util-3.36.0-1.1.el7_6.x86_64                                                                                                                                         7/15 
  Verifying  : nss-softokn-3.36.0-5.el7_5.x86_64                                                                                                                                        8/15 
  Verifying  : nss-softokn-freebl-3.16.2.3-9.el7.x86_64                                                                                                                                 9/15 
  Verifying  : nss-util-3.16.2.3-2.el7.x86_64                                                                                                                                          10/15 
  Verifying  : nss-sysinit-3.16.2.3-5.el7.x86_64                                                                                                                                       11/15 
  Verifying  : nss-tools-3.16.2.3-5.el7.x86_64                                                                                                                                         12/15 
  Verifying  : nss-softokn-3.16.2.3-9.el7.x86_64                                                                                                                                       13/15 
  Verifying  : nss-3.16.2.3-5.el7.x86_64                                                                                                                                               14/15 
  Verifying  : nspr-4.10.6-3.el7.x86_64                                                                                                                                                15/15 

Dependency Installed:
  nss-pem.x86_64 0:1.0.3-5.el7                                                                                                                                                               

Updated:
  nss.x86_64 0:3.36.0-7.1.el7_6                                                                                                                                                              

Dependency Updated:
  nspr.x86_64 0:4.19.0-1.el7_5                nss-softokn.x86_64 0:3.36.0-5.el7_5         nss-softokn-freebl.x86_64 0:3.36.0-5.el7_5         nss-sysinit.x86_64 0:3.36.0-7.1.el7_6        
  nss-tools.x86_64 0:3.36.0-7.1.el7_6         nss-util.x86_64 0:3.36.0-1.1.el7_6         

Complete!
2、重新测试华南内网新域名OK
[root@A06-R12-302F0714-I12-86 --PROD-- ~]# curl -I https://s3-internal.cn-south-1.jdcloud-oss.com/a/a -v
* About to connect() to s3-internal.cn-south-1.jdcloud-oss.com port 443 (#0)
*   Trying 100.65.254.3...
* Connected to s3-internal.cn-south-1.jdcloud-oss.com (100.65.254.3) 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_ECDHE_RSA_WITH_AES_256_CBC_SHA
* Server certificate:
* 	subject: CN=*.s3.cn-north-1.jdcloud-oss.com,O="BEIJING JINGDONG SHANGKE INFORMATION TECHNOLOGY CO., LTD.",L=beijing,ST=beijing,C=CN
* 	start date: Jan 29 09:31:09 2019 GMT
* 	expire date: Jan 30 09:31:09 2020 GMT
* 	common name: *.s3.cn-north-1.jdcloud-oss.com
* 	issuer: CN=GlobalSign Organization Validation CA - SHA256 - G2,O=GlobalSign nv-sa,C=BE
> HEAD /a/a HTTP/1.1
> User-Agent: curl/7.29.0
> Host: s3-internal.cn-south-1.jdcloud-oss.com
> Accept: */*
> 
< HTTP/1.1 404 Not Found
HTTP/1.1 404 Not Found
< Server: JDCloudOSS
Server: JDCloudOSS
< Date: Mon, 11 Mar 2019 04:54:29 GMT
Date: Mon, 11 Mar 2019 04:54:29 GMT
< Content-Length: 0
Content-Length: 0
< Connection: keep-alive
Connection: keep-alive
< x-req-id: ABE7F53066B4B389
x-req-id: ABE7F53066B4B389

< 
* Connection #0 to host s3-internal.cn-south-1.jdcloud-oss.com left intact
  • 结论:nss版本问题导致curl报错
  • 处理方法:yum update nss
<think> 我们分析用户的问题:在应用服务器上使用curl访问http://127.0.0.1:1900报错404,需要解决方案。 参考提供的引用信息,我们发现有几个关键点: 1. 引用[1]中提到,当curl出现连接拒绝时,可能是由于本地代理设置(如http_proxy)指向了错误的端口(如1080),导致连接被拒绝。但用户的问题是404,而不是连接拒绝,所以可能不是代理问题。 2. 引用[2]是关于git配置代理的,同样涉及连接拒绝,与用户问题(404)不同。 3. 引用[3]中提到了404错误,但是是在访问特定URL(/api/projects/110/import)时出现的,这可能是由于服务端没有该路径导致的。 4. 引用[4]是关于端口冲突导致服务启动失败,进而连接失败的问题。 用户的问题:curl访问http://127.0.0.1:1900返回404(Not Found)。这意味着请求发送到了服务器,但服务器没有找到对应的资源。 因此,我们需要关注: - 服务是否在127.0.0.1:1900上正确运行? - 服务是否提供了用户请求的路径? 解决步骤: 1. 确认服务运行状态:首先检查应用服务器上是否有服务监听在127.0.0.1:1900端口。 可以使用命令:`netstat -tuln | grep 1900` 如果没有任何输出,说明没有服务监听1900端口,需要启动对应的服务。 2. 如果服务已经运行,那么检查服务是否提供了根路径("/")的资源。因为用户使用的是`http://127.0.0.1:1900`,这实际上是请求根路径。 有时候服务可能只监听了特定路径,比如需要访问`http://127.0.0.1:1900/somepath`。 3. 检查服务的配置文件,确保它配置了正确的监听地址和端口,并且设置了正确的路由(特别是根路径)。 4. 如果服务运行正常,但访问404,可能是服务内部路由配置问题,需要检查服务日志。 5. 另外,也要注意是否有代理设置干扰。虽然404错误通常不是代理导致的,但有时代理设置错误可能会导致请求被转发到错误的地址,从而出现404。可以检查环境变量中是否有http_proxy设置(如引用[1]所述),尝试取消代理设置再测试: 在命令行中,可以临时取消代理: unset http_proxy unset https_proxy 然后再执行curl命令。 6. 如果服务在本地运行,也可以尝试使用浏览器访问http://127.0.0.1:1900,看是否同样返回404,以确认问题。 7. 如果服务是用户自己部署的,还要确认服务的健康端点(如果有)是否正常,例如`http://127.0.0.1:1900/health`。 8. 如果服务是通过容器或特定进程管理器运行的,检查日志以获取更多信息。 根据引用[3]中提到的404,我们可以推测可能是路径不存在。因此,重点检查服务是否提供了所请求的路径。 总结解决方案: 步骤1:验证服务是否在1900端口运行。 步骤2:验证服务是否响应根路径请求(或尝试访问服务提供的有效路径)。 步骤3:检查服务配置和日志。 步骤4:排除代理干扰。 由于用户的问题描述中明确是404错误,所以我们的重点应放在服务本身是否提供了请求的资源上。 生成相关问题: 1. 如何检查应用服务器上某个端口(如1900)是否有服务在运行? 2. 如何查看服务的日志以诊断404错误? 3. 如何取消环境中的代理设置? 4. 服务在本地运行,但通过curl访问返回404,如何进一步排查? 注意:用户的问题是关于应用服务器上的curl访问,所以我们需要给出在服务器上执行的命令和步骤。 </think> ### 解决方案:应用服务器上 curl 访问 `http://127.0.0.1:1900` 报错 404 的排查步骤 #### 1. **确认服务是否正常运行** - 检查端口监听状态: ```bash # Linux netstat -tuln | grep 1900 # Windows netstat -ano | findstr 1900 ``` - 如果无输出,说明服务未启动或未监听 1900 端口,需启动对应服务。 - 如果有输出,检查进程 ID 是否匹配实际服务(参考引用[4]端口冲突场景)。 - 验证服务健康状态: ```bash # 检查服务进程是否存在 ps aux | grep <服务名> # Linux tasklist | findstr <服务名> # Windows ``` #### 2. **排查代理配置干扰** - **取消代理设置**(参考引用[1][2]): ```bash # 临时关闭代理 unset http_proxy https_proxy # Linux set http_proxy= & set https_proxy= # Windows ``` - 重新测试 `curl http://127.0.0.1:1900`。 - **检查环境变量**: ```bash env | grep -i proxy # Linux set | findstr -i proxy # Windows ``` 若输出类似 `http_proxy=127.0.0.1:1080`,需删除或修正该变量。 #### 3. **检查服务配置** - **路径与路由问题**(参考引用[3]): - 确保请求路径存在(404 表示资源未找到)。 - 例如若服务实际路径为 `/api`,则需访问 `http://127.0.0.1:1900/api`。 - **配置文件检查**: - 检查服务配置文件(如 Nginx/Apache 的 `server` 块)是否包含根路径路由。 - 确认监听的端口是否为 `1900` 且绑定到 `127.0.0.1`。 #### 4. **解决端口冲突**(参考引用[4]) - 若服务启动时报端口冲突: ```bash # 示例:为服务指定独占端口范围 your_service_command --port=1900 --min-worker-port=20000 --max-worker-port=20100 ``` - 检查是否有其他进程占用 1900 端口: ```bash lsof -i :1900 # Linux netstat -ano | findstr 1900 # Windows ``` #### 5. **日志诊断** - 查看服务日志定位具体错误: ```bash # 通用日志路径(根据实际服务调整) tail -f /var/log/service_name/error.log # Linux Get-Content "C:\logs\service.log" -Wait # Windows ``` - 重点关注日志中的 `404` 错误来源及路由匹配失败信息。 #### 6. **防火墙/SELinux 检查** - 确保防火墙允许本地回环访问: ```bash # Linux iptables -L -n -v | grep 1900 # Windows netsh advfirewall firewall show rule name=all | findstr 1900 ``` - 临时禁用防火墙测试: ```bash systemctl stop firewalld # CentOS ufw disable # Ubuntu Set-NetFirewallProfile -Enabled False # Windows PowerShell ``` --- ### 总结流程图 ```mermaid graph TD A[curl 报错404] --> B{服务是否运行?} B -->|否| C[启动服务并监听1900端口] B -->|是| D{代理是否干扰?} D -->|是| E[取消http_proxy环境变量] D -->|否| F{端口是否冲突?} F -->|是| G[修改服务端口或释放端口] F -->|否| H{路径是否正确?} H -->|否| I[修正请求路径或服务路由配置] H -->|是| J[检查防火墙/SELinux] J --> K[查看服务日志] K --> L[定位具体错误原因] ``` --- ### 相关问题 1. 如何快速检测服务器上某个端口(如 1900)是否被正确监听? 2. 当服务日志显示 `Permission denied` 时该如何处理? 3. 如何区分网络问题(如 `Connection refused`)和业务错误(如 `404 Not Found`)? 4. 在 Docker 容器中运行的服务访问 `127.0.0.1` 报错可能是什么原因?
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值