dockerapacheamazon-ec2symfony6mercure

Failed to send an update with Mercure in docker using symfony 7 in production . 404 Not found returned for MERCURE_URL


I am creating an API, and i'm having an issue sending updates to Mercure Hub with symfony 7. I have follow the Symfony current doc and implement Mercure with docker(only mercure). in my local, all working fine, i send update, but in production, it's failed to send update. The error return me "Failed to send an update." and "HTTP/2 404 returned for "https://example.com/.well-known/mercure"." this route is the MERCURE_URL setting in the env variable. I'm using ec2 AWS Linux Machine and i don't use any domaine or SSL certificate, i only use the IP of the Linux Machine to connect. I also use Apache server. Error Images : enter image description here enter image description here Here is my files like in the symfony current doc : compose.override.yaml

version: '3'

services:
###> symfony/mercure-bundle ###
  mercure:
    ports:
      - "80"
###< symfony/mercure-bundle ###

docker-compose.yaml

services:
###> symfony/mercure-bundle ###
  mercure:
    image: dunglas/mercure
    restart: unless-stopped
    environment:
      SERVER_NAME: ':80'
      MERCURE_PUBLISHER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
      MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
      # Set the URL of your Symfony project (without trailing slash!) as value of the cors_origins directive
      MERCURE_EXTRA_DIRECTIVES: |
        cors_origins http://127.0.0.1:8000
    # Comment the following line to disable the development mode
    command: /usr/bin/caddy run --config /etc/caddy/Caddyfile.dev
    volumes:
      - mercure_data:/data
      - mercure_config:/config
###< symfony/mercure-bundle ###

volumes:
###> symfony/mercure-bundle ###
  mercure_data:
  mercure_config:
###< symfony/mercure-bundle ###

.env

###> 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://example.com/.well-known/mercure
# The public URL of the Mercure hub, used by the browser to connect
MERCURE_PUBLIC_URL=https://example.com/.well-known/mercure
# The secret used to sign the JWTs
MERCURE_JWT_SECRET="!ChangeThisMercureHubJWTSecretKey!"
###< symfony/mercure-bundle ###

config/packages/mercure.yaml

mercure:
    hubs:
        default:
            url: '%env(MERCURE_URL)%'
            public_url: '%env(MERCURE_PUBLIC_URL)%'
            jwt:
                secret: '%env(MERCURE_JWT_SECRET)%'
                publish: '*'

my Apache configuration /etc/apache2/sites-available/taxis-chrono.conf

<VirtualHost *:80>
    ServerName localhost

    # Uncomment the following line to force Apache to pass the Authorization
    # header to PHP: required for "basic_auth" under PHP-FPM and FastCGI
    #
    # SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1

    # <FilesMatch \.php$>
        # when using PHP-FPM as a unix socket
       # SetHandler proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://dummy

        # when PHP-FPM is configured to use TCP
        # SetHandler proxy:fcgi://127.0.0.1:9000
    # </FilesMatch>

    DocumentRoot /var/www/taxis-chrono/public
    <Directory /var/www/taxis-chrono/public>
        AllowOverride None
        Require all granted
        FallbackResource /index.php
    </Directory>

    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeeScript assets
    # <Directory /var/www/project>
    #     Options FollowSymlinks
    # </Directory>

    ErrorLog /var/log/apache2/taxis-chrono_error.log
    CustomLog /var/log/apache2/taxis-chrono_access.log combined
</VirtualHost>

Need help please.


Solution

  • I finaly found for the solution after days of searching. It is my mercure docker who was the matter. It was starting up but does not comunicate with the symfony app. What i do is to setting up the port in my compose.override.yaml like this:

    
    services:
    ###> symfony/mercure-bundle ###
      mercure:
        ports:
          - "3000:80"
    ###< symfony/mercure-bundle ### 
    

    and in my .env, i change the MERCURE_URL and like this :

    # 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://127.0.0.1:3000/.well-known/mercure
    # The public URL of the Mercure hub, used by the browser to connect
    MERCURE_PUBLIC_URL=http://127.0.0.1:3000/.well-known/mercure
    # The secret used to sign the JWTs
    MERCURE_JWT_SECRET="!ChangeThisMercureHubJWTSecretKey!"
    ###< symfony/mercure-bundle ###
    

    and now all work fine, my symfony app and my Mercure in docker communicate efficiently. I hope this answer will help some body else.