簡體   English   中英

Symfony + Mercure 連接問題。 使用 HTTPS 代替 HTTP

[英]Symfony + Mercure connection problems. Use HTTPS instead of HTTP

我試圖在兩個 docker 容器之間建立連接。 一個是 nginx 服務器 + Symfony 應用程序,第二個是美居。

我的應用程序運行良好,docker-compose 構建也可以正常運行。 問題是當我嘗試對其進行測試並嘗試從 Symfony 應用程序向 Mercure 發布內容時,我收到 500 個內部服務器錯誤,並顯示“無法發送更新”。 信息。

在堆棧跟蹤中,我可以看到我得到了 TransportException 錯誤,其 env 變量與我在.env文件中的不同。 應用程序正在嘗試使用 HTTPS 而不是在.env 文件中定義的 HTTP。

Symfony\Component\HttpClient\Exception\TransportException:“https://mercure/.well-known/mercure”的 SSL 連接錯誤。 在供應商/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_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,當我發布到美居主題時:

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"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM