1

我正在尝试编写与 Symfony 5 和 Mercure 的聊天代码,但配置存在一些问题。我使用 Windows 10。

这是我遵循的文档:https ://github.com/dunglas/mercure/blob/main/docs/hub/install.md

我在我的项目中安装了这个版本:mercure_0.13.0_Windows_arm64.zip。然后,我解压它,然后在我的终端中,我运行“ composer require symfony/mercure”。

这是在我的.env

# 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="!ChangeMe!"
###< symfony/mercure-bundle ###```

Then I ran the Mercure server with this command line : ```$env:MERCURE_PUBLISHER_JWT_KEY='!ChangeMe!'; $env:MERCURE_SUBSCRIBER_JWT_KEY='!ChangeMe!'; .\mercure.exe run -config Caddyfile.dev```.

In my PowerShell, I have this : 
```2021/11/16 01:39:58.029 INFO    http    server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS {"server_name": "srv0", "https_port": 443}
2021/11/16 01:39:58.029 INFO    http    enabling automatic HTTP->HTTPS redirects        {"server_name": "srv0"}
2021/11/16 01:39:58.111 INFO    tls     cleaning storage unit   {"description": "FileStorage:C:\\Users\\toufi\\AppData\\Roaming\\Caddy"}
2021/11/16 01:39:58.113 INFO    tls     finished cleaning storage units
2021/11/16 01:39:58.134 INFO    pki.ca.local    root certificate is already trusted by system   {"path": "storage:pki/authorities/local/root.crt"}
2021/11/16 01:39:58.135 INFO    http    enabling automatic TLS certificate management   {"domains": ["localhost"]}
2021/11/16 01:39:58.136 WARN    tls     stapling OCSP   {"error": "no OCSP stapling for [localhost]: no OCSP server specified in certificate"}
2021/11/16 01:39:58.143 INFO    autosaved config (load with --resume flag)      {"file": "C:\\Users\\toufi\\AppData\\Roaming\\Caddy\\autosave.json"}
2021/11/16 01:39:58.143 INFO    serving initial configuration```

It seems to run well, but in my browser when I run ```https://localhost/.well-known/mercure```,
I have :
```Not Found
The requested URL was not found on this server.

Apache/2.4.46 (Win64) OpenSSL/1.1.1h PHP/7.4.25 Server at localhost Port 443```

Someone can help me because I don't know how to access to my Mercure server with my browser ?

Thank you very much
4

2 回答 2

1

嘿,本,您应该尝试https://localhost:8000/.well-known/mercure在您的浏览器中运行,而不是https://localhost/.well-known/mercure

于 2021-11-16T09:26:21.940 回答
0

也许您在过去 3 个月中已经解决了这个问题,但我想到了这件事。

您在开发模式 (Caddyfile.dev) 下启动 Mercure 0.13,允许访问演示页面。(顺便说一句,我错过了这里的日志条目,它告诉您,服务器使用您指定的文件,并且应该类似于{"level":"info","ts":1646214769.1484525,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile.dev","config_adapter":""})您可能想打开此演示页面以查看 Mercure 是否有效。默认 URL 为 https://localhost/.well-known/mercure/ui/。它可能会因您的设置而异。也值得尝试使用 http。

您没有提供 SERVER_NAME 环境变量,所以我假设 caddy 尝试使用 80 和 443 端口。因此symfony 配置中的https://127.0.0.1:8000不起作用。如果已经有一个 web 服务器运行来为 symfony 提供访问,那么 80 可能会失败。您可以使用 SERVER_NAME=:8000 在端口 8000 上启动 mercure,但在这种情况下,它只会是 http,而不是 https。

所以,在你的情况下我会做什么,我会在开发模式下启动mercure,并检查演示页面。如果 http 和 https 尝试都失败,我将使用额外的 SERVER_NAME(例如 8000)启动 mercure 并检查 http://localhost:8000/.well-known/mercure/ui/。如果没有任何问题,其中一个应该可以工作。然后你可以继续配置 symfony 以使用水星服务。

于 2022-03-02T11:20:24.950 回答