我需要根据流程请求即时加载不同的 ssl 证书。我尝试在下面的代码中执行此操作,但服务器仍在处理请求时加载 cert1 证书,而不是像我在代码中尝试执行的那样加载 cert2。
如何动态重新加载不同的证书?可能吗?
代码示例:
<?php
require 'vendor/autoload.php';
$server = new swoole_http_server("192.168.10.10", 443, SWOOLE_BASE, SWOOLE_SOCK_TCP | SWOOLE_SSL);
// setup the location of ssl cert files and key files
$ssl_dir = __DIR__.'/ssl_certs';
$server->set([
'max_conn' => 500,
'daemonize' => false,
'dispatch_mode' => 2,
'buffer_output_size' => 2 * 1024 * 1024,
'ssl_cert_file' => $ssl_dir . '/cert1.local.crt',
'ssl_key_file' => $ssl_dir . '/cert1.local.key',
'open_http2_protocol' => true, // Enable HTTP2 protocol
]);
$server->on('request', function ($request, $response) use ($server) {
$server->set([
'ssl_cert_file' => $ssl_dir . '/cert2.local.crt',
'ssl_key_file' => $ssl_dir . '/cert2.local.key',
]);
$response->end("<h1>Hello World. #".rand(1000, 9999)."</h1>");
});
$server->start();