首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Symfony 5 Mercure无法为"https://127.0.0.1:8000/.well-known/mercure“”发送更新SSL连接错误

Symfony 5 Mercure无法为"https://127.0.0.1:8000/.well-known/mercure“”发送更新SSL连接错误
EN

Stack Overflow用户
提问于 2021-06-26 23:27:15
回答 1查看 655关注 0票数 2

我是学生和初学者,如果我听不懂,请提前道歉。我尝试将Symfony 5与mercure一起使用,但我在向集线器发送更新时遇到一些困难。我将文档检查到Symfony Mercure doc,并认为这是一个很好的部分,但不是全部。

我已经在我的Windows10上安装了docker,我直接通过Symfony cli安装了Mercure,就像在文档上写的那样。我的参数是cli默认安装的参数。.env

代码语言:javascript
复制
        ###> symfony/mercure-bundle ###
    # See https://symfony.com/doc/current/mercure.html#configuration
    # The URL of the Mercure hub, used by the app to publish updates (can be a local URL)
    MERCURE_URL=https://127.0.0.1:8000/.well-known/mercure
    # The public URL of the Mercure hub, used by the browser to connect
    MERCURE_PUBLIC_URL=https://127.0.0.1:8000/.well-known/mercure
    # The secret used to sign the JWTs
    MERCURE_JWT_SECRET="secret"
###< symfony/mercure-bundle ###

我使用一个真正的JWT的秘密只是为了例子(JWT.io)2

代码语言:javascript
复制
{
  "mercure": {
    "publish": [
      "*"
    ]
  }
}

用我的秘密密码。

我用eventSource创建了一个js文件。

代码语言:javascript
复制
const eventSource = new EventSource('http://127.0.0.1:8000/.well-known/mercure?topic=' + encodeURIComponent('http://127.0.0.1:8000/commande/recapitulatif'),
    );
eventSource.onmessage = event => {
    // Will be called every time an update is published by the server
    alert("Commande");
    console.log(JSON.parse(event.data));
}

我希望在有人访问recap时发送通知:http://127.0.0.1:8000/commande/recapitulatif。在我的控制器中,当地址http://127.0.0.1:8000/commande/recapitulatif被调用时,我添加:

代码语言:javascript
复制
 $update = new Update(
            'http://127.0.0.1:8000/commande/recapitulatif',
            json_encode(['status' => 'Commande'])
        );

        $hub->publish($update);

在我需要通知并添加js代码的页面上,如果我在chrome的app dev的网络中检查mercure的连接,我可以看到:

代码语言:javascript
复制
Request URL: http://127.0.0.1:8000/.well-known/mercure?topic=http%3A%2F%2F127.0.0.1%3A8000%2Fcommande%2Frecapitulatif
Request Method: GET
Status Code: 200 OK
Remote Address: 127.0.0.1:8000
Referrer Policy: strict-origin-when-cross-origin

但是当我尝试访问url http://127.0.0.1:8000/commande/recapitulatif时,我遇到了一个错误(发送更新失败)和(“https://127.0.0.1:8000/.well-known/mercure".”的SSL连接错误)。

更新:我改变了

代码语言:javascript
复制
MERCURE_URL=https://127.0.0.1:8000/.well-known/mercure

MERCURE_PUBLIC_URL=https://127.0.0.1:8000/.well-known/mercure

代码语言:javascript
复制
MERCURE_URL=http://127.0.0.1:8000/.well-known/mercure

MERCURE_PUBLIC_URL=http://127.0.0.1:8000/.well-known/mercure

现在出现错误(无法发送更新)(HTTP/1.1401未授权返回“http://127.0.0.1:8000/.well-known/mercure".”)

也许我需要把我的应用程序放到https上,以便与mercure建立ssl连接?

另一种尝试。在.env和js文件中,我将https更改为http,并替换了http。之后,我修改了控制器中的代码,如下所示:

代码语言:javascript
复制
 $discovery->addLink($request);

    $response = new JsonResponse([
        '@id' => 'http://127.0.0.1:8000/commande/recapitulatif',
        'status' => 'Order',
    ]);

    $response->headers->setCookie(
        $authorization->createCookie($request, ['http://127.0.0.1:8000/commande/recapitulatif'])
    );

现在我没有错误,但是没有任何东西通知我的浏览器。

我想要通知页面的日志:

代码语言:javascript
复制
[Application] Jun 26 17:33:45 |DEBUG  | SECURI Stored the security token in the session. key="_security_main"
[Web Server ] Jun 26 19:33:45 |INFO   | SERVER GET  (200) /favicon.ico ip="127.0.0.1"
[Application] Jun 26 17:33:46 |INFO   | REQUES Matched route "_wdt". method="GET" request_uri="http://127.0.0.1:8000/_wdt/8f2711" route="_wdt" route_parameters={"_controller":"web_profiler.controller.profiler::toolbarAction","_route
":"_wdt","token":"8f2711"}
[Web Server ] Jun 26 19:33:47 |INFO   | SERVER GET  (200) /_wdt/8f2711 ip="127.0.0.1"

以及我需要发送通知的日志:

代码语言:javascript
复制
[Application] Jun 26 17:36:06 |DEBUG  | SECURI Stored the security token in the session. key="_security_main"
[Web Server ] Jun 26 19:36:06 |INFO   | SERVER POST (200) /commande/recapitulatif host="127.0.0.1:8004" ip="127.0.0.1" scheme="https"
[Application] Jun 26 17:36:07 |INFO   | REQUES Matched route "_wdt". method="GET" request_uri="http://127.0.0.1:8000/_wdt/d13a0f" route="_wdt" route_parameters={"_controller":"web_profiler.controller.profiler::toolbarAction","_route
":"_wdt","token":"d13a0f"}
[Web Server ] Jun 26 19:36:08 |INFO   | SERVER GET  (200) /_wdt/d13a0f ip="127.0.0.1"

但是如果我像这样添加更新:

代码语言:javascript
复制
 $update = new Update(
                'http://127.0.0.1:8000/commande/recapitulatif',
                json_encode(['status' => 'Commande']), true
            );

            $hub->publish($update);

我的日志是这样的:

代码语言:javascript
复制
[Application] Jun 26 18:02:39 |INFO   | HTTP_C Request: "POST http://127.0.0.1:8000/.well-known/mercure"
[Application] Jun 26 18:02:39 |INFO   | HTTP_C Response: "401 http://127.0.0.1:8000/.well-known/mercure"
[Application] Jun 26 18:02:39 |CRITICA| REQUES Uncaught PHP Exception Symfony\Component\Mercure\Exception\RuntimeException: "Failed to send an update." at C:\laragon\www\Projet\Restaurant\RelaisDesVoutes\vendor\symfony\mercure\src\H
ub.php line 104
[Web Server ] Jun 26 20:02:39 |INFO   | MERCUR Topic selectors not matched, not provided or authorization error
[Web Server ] Jun 26 20:02:39 |WARN   | SERVER POST (401) /.well-known/mercure host="127.0.0.1:8004" ip="127.0.0.1" scheme="https"
[Application] Jun 26 18:02:39 |DEBUG  | SECURI Stored the security token in the session. key="_security_main"
[Web Server ] Jun 26 20:02:39 |ERROR  | SERVER POST (500) /commande/recapitulatif host="127.0.0.1:8004" ip="127.0.0.1" scheme="https"

如果有人能帮助我了解我的问题所在,非常感谢。

EN

回答 1

Stack Overflow用户

发布于 2021-08-10 19:54:11

我假设您已经运行并安装了单独的Mercure二进制文件。您不能同时在端口8000上运行Mercure二进制文件和Symfony。根据您的版本(我正在运行Mercure v0.9.0,因为我遵循了一个教程),您也许能够创建一个像这样的Makefile

代码语言:javascript
复制
mercure_server:
    JWT_KEY=my_key ADDR=localhost:3000 ALLOW_ANONYMOUS=1 CORS_ALLOWED_ORIGINS=http://localhost:8000 ./bin/mercure

然后运行make mercure_server

这里假设您的项目的bin目录中有mercure二进制文件。此命令不适用于最新版本的Mercure,因为它不是环境变量的设置方式。

新版本的Mercure二进制文件运行的是经过修改的Caddy服务器版本,从我目前所读到的内容来看,它与Symfony的兼容性并没有得到很好的说明。如果你手头拮据,我会考虑降级到v0.9.0,因为周围有更多可用的资源。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68143814

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档