Cloudflare - 525 SSL握手失败

12

我把我的域名转移到了Cloudflare,现在我正在尝试使用CloudFlare的SSL功能。

我已经拥有StartSSL的SSL证书,所以可以将设置更改为“Full(Strict)”,但我不想这样做,所以我把它改成了“Full”。

现在我遇到了525错误,在“重试获取实时版本”之后一切正常。但是我每次都会遇到这个错误。

有人有主意吗?

谢谢

我的错误图片

6个回答

12

将Cloudflare的SSL/TLS加密模式改为“灵活”即可。这对我有效。


10
如果您这样做,Cloudflare与您的服务器之间将不再有加密的流量。这是不建议的。即使端口443可用并使用TLS进行加密,灵活模式的流量始终会转到端口80。 - Seer

5

525错误表示CloudFlare无法与您的源服务器联系并创建SSL连接。

这可能是由于以下原因:

  • 您的服务器没有匹配或兼容的SSL密码
  • 您的网站可能没有正确安装证书
  • 您的网站可能没有专用IP地址,或未配置使用SNI

请尝试联系您的托管提供商以获取帮助,确保您的SSL证书设置正确。如果您正在使用控制面板,则可以通过快速谷歌搜索找到该控制面板的安装指南。


6
我相信,如果Cloudflare与您的源服务器之间的连接超时,则Cloudflare也会报告此错误。 - Justin Steele

4
请访问Cloudflare中的SSL/TLS选项卡,然后:
  1. 将您的SSL/TLS加密模式切换为“Flexible”。
  2. 确保在“边缘证书”选项卡下打开“始终使用HTTPS”。 enter image description here
这样将自动将所有请求从HTTP转移到HTTPS。如果您在托管服务器上实施自定义SSL证书,则无需更改Cloudflare上的任何内容即可自动消除此525错误。

请列出“将SSL/TLS加密模式切换为Flexible”的原因,可以吗? - Ayyappa

1

我几天前遇到了同样的问题。我们的DevOps联系了支持团队,发现Cloudflare更改了证书类型或类似的东西。要求将一切恢复原状。这有所帮助。


我通过从Cloudflare下载证书并安装在服务器上以确保匹配密码解决了我的问题。 - Chibueze Opata

1
我遇到了同样的问题,特别是在配置了负载均衡和Cloudflare后面的反向代理的WordPress实例中。其他Web应用程序都正常工作,但我在使用Elementor构建的WordPress上遇到了问题。 花了一些时间找到不同链接的参考,并能够理解根本原因。
已经过去一个星期了,暂时没有遇到525错误。所以这里是步骤:
  1. Cloudflare => 将TLS/SSL切换到完全模式。(严格模式会导致连接安全性问题。首先,我认为可能是PHP 8x版本没有适应得当,其次,根据Cloudflare的规定,此功能存在混合内容的限制。因此,不要浪费时间在完全(严格)模式上,只需创建规则来禁用它以供WordPress URL使用或者全局禁用它。我们将在后续步骤中添加一些额外的内容,这可能起到完全(严格)模式的作用。
  2. Cloudflare => 切换到开发模式。(确保我们可以测试绕过Cloudflare缓存)。
  3. Cloudflare => 启用始终使用HTTPS,并从本地Web服务器Apache/Nginx或负载均衡器禁用端口80重定向。这简化了兼容性。
  4. Cloudflare => 启用HTTP严格传输安全(HSTS)。 (可选,保持预加载禁用)。
  5. Cloudflare => 最低TLS版本-1.2。
  6. Cloudflare => 启用TLS 1.3。
  7. Cloudflare => 启用自动HTTPS重写。
  8. Cloudflare => 如果您的WordPress安装了Elementor插件(参考https://elementor.com/help/elementor-and-cloudflare-rocket-loader/)。请确保根据屏幕截图禁用Rocketloader => https://istack.dev59.com/u4Cwl.webp
  9. Cloudflare => 在速度优化部分禁用Rocketloader。
  10. Cloudflare => 使用以下Cloudflare worker创建内容安全策略。这样可以确保如果由于任何网络波动导致520或525错误,浏览器会重新请求。如果您是第一次使用Cloudflare worker,请参考https://developers.cloudflare.com/workers/get-started/guide/。这也可以提供额外的保护措施在Cloudflare上。我复制了下面的两个worker配置 worker.js

export default {
    async fetch(request, env, ctx) {
      if (request.body) {
        // This request has a body, i.e. it's submitting some information to
        // the server, not just requesting a web page. If we wanted to be able
        // to retry such requests, we'd have to buffer the body so that we
        // can send it twice. That is expensive, so instead we'll just hope
        // that these requests (which are relatively uncommon) don't fail.
        // So we just pass the request to the server and return the response
        // nomally.
        return fetch(request);
      }
  
      // Try the request the first time.
      let response = await fetch(request);
      
      if (response.status == 520) {
        // The server returned status 525. Let's retry the request. But
        // we'll only retry once, since we don't want to get stuck in an
        // infinite retry loop.
  
        // Let's discard the previous response body. This is not strictly
        // required but it helps let the Workers Runtime know that it doesn't
        // need to hold open the HTTP connection for the failed request.
        await response.arrayBuffer();
  
        // OK, now we retry the request, and replace the response with the
        // new version.
         response = await fetch(request);
      }

      if (response.status == 525) {
        // The server returned status 525. Let's retry the request. But
        // we'll only retry once, since we don't want to get stuck in an
        // infinite retry loop.
  
        // Let's discard the previous response body. This is not strictly
        // required but it helps let the Workers Runtime know that it doesn't
        // need to hold open the HTTP connection for the failed request.
        await response.arrayBuffer();
  
        // OK, now we retry the request, and replace the response with the
        // new version.
         response = await fetch(request);
      }  
      return response;
    }
  }

worker2.js

export default {
    async fetch(request) {
      const DEFAULT_SECURITY_HEADERS = {
        /*
      Secure your application with Content-Security-Policy headers.
      Enabling these headers will permit content from a trusted domain and all its subdomains.
      @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
      "Content-Security-Policy": "default-src 'self' example.com *.example.com",
      */
      /*"Content-Security-Policy": "script-src 'unsafe-eval' 'unsafe-inline' https:",
        /*
      You can also set Strict-Transport-Security headers.
      These are not automatically set because your website might get added to Chrome's HSTS preload list.
      Here's the code if you want to apply it:
      "Strict-Transport-Security" : "max-age=63072000; includeSubDomains; preload",
      */
      /*"Strict-Transport-Security" : "max-age=63072000; includeSubDomains; preload",
        /*
      Permissions-Policy header provides the ability to allow or deny the use of browser features, such as opting out of FLoC - which you can use below:
      "Permissions-Policy": "interest-cohort=()",
      */
      /*"Permissions-Policy": "interest-cohort=()",
        /*
      X-XSS-Protection header prevents a page from loading if an XSS attack is detected.
      @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection
      */
        "X-XSS-Protection": "0",
        /*
      X-Frame-Options header prevents click-jacking attacks.
      @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
      */
        "X-Frame-Options": "SAMEORIGIN",
        /*
      X-Content-Type-Options header prevents MIME-sniffing.
      @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
      */
        "X-Content-Type-Options": "nosniff",
        "Referrer-Policy": "strict-origin-when-cross-origin",
        "Cross-Origin-Embedder-Policy": 'require-corp; report-to="default";',
        "Cross-Origin-Opener-Policy": 'same-site; report-to="default";',
        "Cross-Origin-Resource-Policy": "same-site",
      };
      const BLOCKED_HEADERS = [
        "Public-Key-Pins",
        "X-Powered-By",
        "X-AspNet-Version",
      ];
  
      let response = await fetch(request);
      let newHeaders = new Headers(response.headers);
  
      const tlsVersion = request.cf.tlsVersion;
      console.log(tlsVersion);
      // This sets the headers for HTML responses:
      if (
        newHeaders.has("Content-Type") &&
        !newHeaders.get("Content-Type").includes("text/html")
      ) {
        return new Response(response.body, {
          status: response.status,
          statusText: response.statusText,
          headers: newHeaders,
        });
      }
  
      Object.keys(DEFAULT_SECURITY_HEADERS).map((name) => {
        newHeaders.set(name, DEFAULT_SECURITY_HEADERS[name]);
      });
  
      BLOCKED_HEADERS.forEach((name) => {
        newHeaders.delete(name);
      });
  
      if (tlsVersion !== "TLSv1.2" && tlsVersion !== "TLSv1.3") {
        return new Response("You need to use TLS version 1.2 or higher.", {
          status: 400,
        });
      } else {
        return new Response(response.body, {
          status: response.status,
          statusText: response.statusText,
          headers: newHeaders,
        });
      }
    },
  };
  /* css*/
  async function handleRequest(request) {
    let resp = await fetch(request.url, request);
  
    let newResp = new Response(resp.body, {
      headers: resp.headers,
      status: resp.status
    })
  
    if (request.url.endsWith(".css")) {
      newResp.headers.set("Content-Type", "text/css");
    }
    if (request.url.endsWith(".js")) {
      newResp.headers.set("Content-Type", "text/javascript");
    }
    return newResp;
  }
  
  addEventListener("fetch", event => event.respondWith(handleRequest(event.request)))
  

Wordpress网页服务器和负载均衡器-如果您使用Apache,请确保443 SSL/TLS密码套件与Cloudflare,负载均衡器(源服务器)和Web服务器(WordPress)上的相同。请查看此链接 https://developers.cloudflare.com/ssl/reference/cipher-suites/ 。 配置Web服务器和负载均衡器VS的SNI。确保启用了重新加密。 在源服务器(负载均衡器)上配置头信息,正确设置持久化模式头信息。(参考https://developers.cloudflare.com/fundamentals/get-started/reference/http-request-headers/#cf-connecting-ip) 请确保源服务器已安装Cloudflare CA RSA证书。ECA认证可能存在问题,我在负载均衡器中禁用了它。(参考https://developers.cloudflare.com/ssl/origin-configuration/origin-ca/#cloudflare-origin-ca-root-certificate) 禁用源服务器(负载均衡器)中的空白头信息。某些WordPress插件会创建空白头信息,如果您的源服务器有全局策略,最好禁用空白头请求。或者解决方案B参考:https://equalizedigital.com/accessibility-checker/empty-heading/#:~:text=How%20to%20find%20empty%20headers%20on%20your%20WordPress%20post%20or%20page,-First%2C%20install%20the&text=For%20any%20pages%20or%20posts,caused%20the%20error%20to%20appear。 使用ssllabs.com/ssltest/来测试您的WordPress。确保您获得了A类别。
根据您在CloudFlare和WordPress之间使用的负载均衡器的类型,可能需要进行一些额外的配置。但是我注意到所有的论坛中好像都缺少上述信息。因此,希望这对您有所帮助。

0

今天我遇到了同样的问题,并发现(至少在我的情况下)缺少TLS v1.3是原因。

我刚刚使用nginx + php-fpm和自签名ssl创建了一个服务器,以在CloudFlare代理下使用。

当我从生产服务器切换到这个新服务器时,它出现了525错误。

我执行了命令:curl -I https://your_server_public_ip/,它返回了错误:

error: 1408F10B: SSL routines: ssl3_get_record: wrong version number

这个错误在CloudFlare社区中有描述: https://community.cloudflare.com/t/community-tip-fixing-error-525-ssl-handshake-failed/44256

他们建议在CloudFlare面板上关闭TLS v1.3,但我决定尝试安装它。

使用nginx非常容易,我不知道为什么要将其关闭。

只需像这样添加TLSv1.3->ssl_protocols TLSv1.2 TLSv1.3;在您的nginx/snippets/ssl-params.conf文件(默认Ubuntu 20和18),这将起作用,并且您仍然可以使用最新和最安全的协议。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接