http: server gave HTTP response to HTTPS client

发布时间 2023-04-20 00:33:17作者: 让速不让路

The error message "http: server gave HTTP response to HTTPS client" occurs when a client tries to access a server through an HTTPS connection, but the server only supports HTTP. This error is commonly seen when using Docker to interact with a private registry, as Docker defaults to HTTPS communication with registries since version 1.3. There are a few ways to solve this problem, depending on the situation.

One solution is to configure Docker to use HTTP communication with the private registry. To do this, you can add the --insecure-registry option when starting the Docker daemon. This option tells Docker to allow communication with the registry over HTTP. For example, if the private registry is hosted at ip:5000, you can start Docker with the following command:

sudo dockerd --insecure-registry ip:5000

However, using the --insecure-registry option is not recommended for production environments, as it disables Docker's security features. Instead, you can configure the private registry to support HTTPS communication by setting up a reverse proxy or using a tool like stunnel to encrypt the communication.

Another solution is to configure the client to use HTTPS communication with the server, if supported. For example, if you are using kubectl to interact with a Kubernetes cluster, you can specify the protocol to use when accessing the private registry by adding the --insecure-skip-tls-verify=false option. This option tells kubectl to use HTTPS communication with the registry, and to verify the server's TLS certificate.

It's worth noting that if the server does not support HTTPS communication, using HTTPS on the client side will not work. In this case, you will need to either enable HTTPS on the server or use a different tool that supports HTTP communication.

Sources: