我正在使用symfony二进制文件中的mercure。通过以下方式设置新项目后
symfony new mercure
cd mercure
symfony composer req make mercure annotations
symfony console make:controller
symfony server:start我在新创建的控制器中编写了一些最小的代码:
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update;
class MainController extends AbstractController
{
/**
* @Route("/", name="main")
*/
public function index(HubInterface $hub): Response
{
$update = new Update(
'http://mercure/asdf',
json_encode(['message' => 'heyo']),
);
$hub->publish($update);
return $this->json([
'message' => 'Welcome to your new controller!',
'path' => 'src/Controller/MainController.php',
]);
}
}然后,我从here (链接自symfony文档)生成一个JWT密钥,并在右下角输入!ChangeMe!,因为这是symfony二进制文件使用的密钥。然后在.env中设置JWT密钥
MERCURE_URL=https://127.0.0.1:8000/.well-known/mercure
MERCURE_PUBLIC_URL=https://127.0.0.1:8000/.well-known/mercure
MERCURE_JWT_SECRET=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOlsiKiJdfX0.obDjwCgqtPuIvwBlTxUEmibbBf0zypKCNzNKP7Op2UM在重启服务器并转到localhost:8000之后,我得到了Failed to send an update.和HTTP/2 401 returned for "https://localhost:8000/.well-known/mercure".,这可能是因为密钥不能正常工作。服务器上出现错误:MERCUR Topic selectors not matched, not provided or authorization error
通过设置MERCURE_JWT_SECRET="!ChangeMe!" (不加密),如果从运行服务器的计算机访问站点,但不是从同一网络中的其他计算机(通过192.168.XXX.XXX:8000)访问站点,则可以正常工作。
我做错了什么?
发布于 2021-08-25 08:23:16
原来是我的操作系统的配置出了问题。在把项目推到另一台机器上之后,一切都运行得很好。
https://stackoverflow.com/questions/68861691
复制相似问题