NGINX:400 纯 HTTP 请求已发送到 HTTPS 端口

hel*_*y77 2 ssl nginx

我将 nginx 设置为 docker 注册表的 proxypass,协议 http 有效,但如果我设置了 https,我有: 400 The plain HTTP request was sent to HTTPS port

这是我的 nginx 配置文件:

upstream docker-registry {
 server 127.0.0.1:5000;
}

server {
 listen 443 ssl;
 server_name docker-registry.mydomain.it;

  ssl_certificate /etc/ssl/certs/docker-registry;
  ssl_certificate_key /etc/ssl/private/docker-registry;

 proxy_set_header Host       $http_host;   # required for Docker client sake
 proxy_set_header X-Real-IP  $remote_addr; # pass on real client IP

 client_max_body_size 0; # disable any limits to avoid HTTP 413 for large image uploads

 # required to avoid HTTP 411: see Issue #1486 (https://github.com/dotcloud/docker/issues/1486)
 chunked_transfer_encoding on;

 location / {
     # let Nginx know about our auth file
     auth_basic              "Restricted";
     auth_basic_user_file    docker-registry.htpasswd;
     proxy_pass http://docker-registry;
 }
 location /_ping {
     auth_basic off;
     proxy_pass http://docker-registry;
 }
 location /v1/_ping {
     auth_basic off;
     proxy_pass http://docker-registry;
 }

}
Run Code Online (Sandbox Code Playgroud)

小智 5

添加:

proxy_set_header X-Forwarded-Proto $scheme;
Run Code Online (Sandbox Code Playgroud)

  • 欢迎来到 Unix 和 Linux!虽然此代码片段可能会解决问题,但包括解释[确实有帮助](//meta.stackexchange.com/q/114762) 以提高您的帖子质量。请记住,您是在为未来的读者回答问题,而不仅仅是现在问的人!请[编辑]您的答案以添加解释,并说明适用的限制和假设。 (4认同)