gpt4 book ai didi

php - Symfony + Mercure 连接问题。使用 HTTPS 而不是 HTTP

转载 作者:行者123 更新时间:2023-12-05 04:50:39 25 4
gpt4 key购买 nike

我试图在两个 docker 容器之间建立连接。一个作为 nginx 服务器 + Symfony 应用程序,第二个使用 Mercure。

我的应用程序运行良好,docker-compose 构建也没有任何问题。问题是当我尝试测试它并尝试从 Symfony 应用程序向 Mercure 发布某些内容时,我遇到了 500 内部服务器错误“无法发送更新”。消息。

在堆栈跟踪中,我可以看到我遇到了 TransportException 错误,它的环境变量与我在 .env 文件中的环境变量不同。应用程序正在尝试使用 HTTPS 而不是 .env 文件中定义的 HTTP。

Symfony\Component\HttpClient\Exception\TransportException:SSL connect error for "https://mercure/.well-known/mercure".at vendor/symfony/http-client/Chunk/ErrorChunk.php:65

###> 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=http://mercure/.well-known/mercure

# The public URL of the Mercure hub, used by the browser to connect
MERCURE_PUBLIC_URL=http://localhost:9090/.well-known/mercure

MERCURE_PUBLISH_URL=http://mercure/.well-known/mercure

# The secret used to sign the JWTs
MERCURE_JWT_SECRET=<Proper JWT Token is here>
###< symfony/mercure-bundle ###

在 Mercure 容器中我得到:

mercure_1   | {"level":"debug","ts":1619097073.714639,"logger":"http.stdlib","msg":"http: TLS handshake error from 172.21.0.5:57420: no certificate available for 'mercure'"}

我的 docker-compose 配置

services:

api:
build:
context: ./api
dockerfile: Dockerfile
volumes:
- ./api:/app
- ./api/storage/logs/php-fpm:/var/log/php-fpm
networks:
- redio_network
ports:
- "7000:80"
environment:
<<: *common-variables

mercure:
image: dunglas/mercure
environment:
MERCURE_PUBLISHER_JWT_KEY: '!ChangeMe!'
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeMe!'
ports:
- "9090:80"
networks:
- redio_network
volumes:
- ./_data/caddy_data:/data
- ./_data/caddy_config:/config
command: /usr/bin/caddy run -config /etc/caddy/Caddyfile.dev

这是我的 Controller ,当我发布到 Mercure 主题时:

class ChatController extends AbstractController
{
/**
* @Route("/push", name="push")
* @param Request $request
* @param HubInterface $publisher
* @return Response
*/
public function push(Request $request, HubInterface $publisher): Response
{
$publisher->publish(new Update(
'/chat',
json_encode(['message' => 'hello!'])
));

return $this->json('Done');
}
}

最佳答案

好的,我找到了。如果有人遇到同样的问题,请将 SERVER_NAME 变量添加到您的 docker-compose 配置中。 Mercure 使用默认设置为强制 HTTPS 的 Caddy 服务器。

mercure:
image: dunglas/mercure
environment:
MERCURE_PUBLISHER_JWT_KEY: '!ChangeMe!'
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeMe!'
SERVER_NAME: ":80"

关于php - Symfony + Mercure 连接问题。使用 HTTPS 而不是 HTTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67214389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com