在 Azure 云服务上配置 Wordpress 以通过 SSL 连接到 Azure MySQL

Jez*_*ers 6 php mysql wordpress ssl azure

我们在云服务上的主要 .NET 解决方案的子文件夹中运行 Wordpress。我们已将 MySQL 从 CloudDB 移至 Azure MySQL,但是只有在我们将“强制 SSL 连接”设置为禁用时它才会连接。

Wordpress wp-config.php 有以下内容

define('DB_SSL', true);
Run Code Online (Sandbox Code Playgroud)

我认为问题是我们需要传递证书,但我不清楚我们如何在 Wordpress 中设置它,以便在通过 SSL 连接时传递它。

Aar*_*hen 3

这是我所做的:

  1. 获取 SSL 证书并将证书文件保存到我的 Wordpress 项目的根目录中。

  2. 将以下内容添加到wp-config.php

    define('DB_SSL', true);
    
    Run Code Online (Sandbox Code Playgroud)
  3. 将其添加到db_connect()我的wp-includes/wp-db.php. 必须在以下之前调用mysqli_real_connect()

    // Just add this line
    mysqli_ssl_set($this->dbh, NULL, NULL, ABSPATH . 'BaltimoreCyberTrustRoot.crt.pem', NULL, NULL); 
    
    if ( WP_DEBUG ) {
        mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
    } else {
        @mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
    }
    
    Run Code Online (Sandbox Code Playgroud)

该解决方案看起来有点脏,但它对我有用。

  • 不建议修改WP的核心文件。WP 更新后会发生什么?每次升级WP都需要这样做吗? (2认同)