How to affect kernel request hostname when bootstrapping from custom PHP script
You need to use the HTTP_HOST instead the SERVER_NAME, also you can pass it as $server param to the Request::create()

$autoloader = require_once 'web/autoload.php';
$request = Request::create('/', 'GET', [], [], [], ["HTTP_HOST" =&gt; 'whatever']);
$this-&gt;kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$this-&gt;kernel-&gt;boot();
$this-&gt;kernel-&gt;prepareLegacyRequest($request);


Remember to add the hostname to $settings['trusted_host_patterns']