skip to Main Content

I am contacting you because I can’t get mercure to work in production.

The binary prebuild runs fine, but when I try to connect to the hub, I get a 404 no found.

Here is the command I run :

sudo MERCURE_PUBLISHER_JWT_KEY='eyJhbGciOiJIUzI1NiIsInR5cCI6...' MERCURE_SUBSCRIBER_JWT_KEY='eyJhbGciOiJIUzI1NiIsInR5cCI6...' SERVER_NAME=:3000 ./mercure run

the server launches without any problem apparently:

2022/02/15 17:38:09.919 INFO    using adjacent Caddyfile
2022/02/15 17:38:09.920 WARN    input is not formatted with 'caddy fmt' {"adapter": "caddyfile", "file": "Caddyfile", "line": 3}
2022/02/15 17:38:09.921 INFO    admin   admin endpoint started  {"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["[::1]:2019", "127.0.0.1:2019", "localhost:2019"]}
2022/02/15 17:38:09.922 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc0000cb7a0"}
2022/02/15 17:38:09.935 INFO    tls     cleaning storage unit   {"description": "FileStorage:/root/.local/share/caddy"}
2022/02/15 17:38:09.935 INFO    tls     finished cleaning storage units
2022/02/15 17:38:09.935 INFO    autosaved config (load with --resume flag)      {"file": "/root/.config/caddy/autosave.json"}
2022/02/15 17:38:09.935 INFO    serving initial configuration

my .env is configured as such:

###> symfony/mercure-bundle ###
MERCURE_URL=https://monsite.com/.well-known/mercure
MERCURE_PUBLIC_URL=https://monsite.com/.well-known/mercure
MERCURE_JWT_SECRET="eyJhbGciOiJIUzI1NiIsInR5cCI6..."
###< symfony/mercure-bundle ###

My CaddyFile :

# Learn how to configure the Mercure.rocks Hub on https://mercure.rocks/docs/hub/config
{
        {$GLOBAL_OPTIONS}
}

{$SERVER_NAME:monsite.com}

log

route {
        encode zstd gzip

        mercure {
                # Transport to use (default to Bolt)
                transport_url {$MERCURE_TRANSPORT_URL:bolt://mercure.db}
                # Publisher JWT key
                publisher_jwt {env.MERCURE_PUBLISHER_JWT_KEY} {env.MERCURE_PUBLISHER_JWT_ALG}
                # Subscriber JWT key
                subscriber_jwt {env.MERCURE_SUBSCRIBER_JWT_KEY} {env.MERCURE_SUBSCRIBER_JWT_ALG}
                # Allow Subscribers
                anonymous
                # Extra directives
                {$MERCURE_EXTRA_DIRECTIVES}
        }

        respond /healthz 200

        respond "Not Found" 404
}

When I try to access the hub with postman by typing the following command:

https://monsite.com/.well-known/mercure

I get a 404 no found.

I am under linux debian 10 with apache2. I don’t understand what I did wrong. Thanks for your help.

EDIT 21/02/2022

Hi Mehmet, here is what I did:

In /etc/apache2/sites-available monsite.conf and monsite-le-ssl.conf :

ProxyPass /mercure-hub http://localhost:8080/
ProxyPassReverse /mercure-hub http://localhost:8080/

In Caddyfile and Caddyfile.dev :

{
        {$GLOBAL_OPTIONS}
        auto_https off }

{$SERVER_NAME::8080}

Apparently the hub launches well, I have no error in the console:

debian@vps-...:/var/www/monsite/mercure$ sudo MERCURE_PUBLISHER_JWT_KEY='eyJhbGciOiJIUzI1NiIsInR5cCI6I...' MERCURE_SUBSCRIBER_JWT_KEY='eyJhbGciOiJIUzI1NiIsInR5cCI6I...' ./mercure run -config Caddyfile.dev
2022/02/21 13:31:20.672 INFO    using provided configuration    {"config_file": "Caddyfile.dev", "config_adapter": ""}
2022/02/21 13:31:20.675 WARN    input is not formatted with 'caddy fmt' {"adapter": "caddyfile", "file": "Caddyfile.dev", "line": 3}
2022/02/21 13:31:20.676 INFO    admin   admin endpoint started  {"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["localhost:2019", "[::1]:2019", "127.0.0.1:2019"]}
2022/02/21 13:31:20.676 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc0003fe700"}
2022/02/21 13:31:20.703 INFO    tls     cleaning storage unit   {"description": "FileStorage:/root/.local/share/caddy"}
2022/02/21 13:31:20.703 INFO    tls     finished cleaning storage units
2022/02/21 13:31:20.703 INFO    autosaved config (load with --resume flag)      {"file": "/root/.config/caddy/autosave.json"}
2022/02/21 13:31:20.704 INFO    serving initial configuration

Whether I run Caddyfile or Caddyfile.dev, when accessing https://monsite.com/mercure-hub, I get a 500 error.

2

Answers


  1. Chosen as BEST ANSWER

    After some digging, I tried to figure out why it was returning a 500 error. I went to the apache logs, I had this error message:

    "No protocol handler was valid for the URL /. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule"

    So I installed the missing components:

    sudo a2enmod ssl
    sudo a2enmod proxy
    sudo a2enmod proxy_balancer
    sudo a2enmod proxy_http
    

    I also modified the proxy urls by adding a slash at the end of mercure-hub, otherwise I would get a 404 error:

     ProxyPass /mercure-hub/ http://localhost:8080/
     ProxyPassReverse /mercure-hub/ http://localhost:8080/
    

    Restarted apache, and updated the Url in my .env :

    MERCURE_URL=https://monsite.com/mercure-hub/.well-known/mercure
    MERCURE_PUBLIC_URL=https://monsite.com/mercure-hub/.well-known/mercure 
    

    And it works, thanks a lot !


  2. That is my apache settings. Maybe help to you.

    open
    nano /etc/apache2/sites-available/yourdomain.com-le-ssl.conf

    <IfModule mod_ssl.c>
    <VirtualHost *:443>
            DocumentRoot /var/www/html/yourdomain.com
            DirectoryIndex /index.php
            ServerName yourdomain.com
    
        #Settings for mercure
            ProxyPass      /mercure-hub     http://localhost:8080
            ProxyPassReverse /mercure-hub   http://localhost:8080
    
    
            <Directory /var/www/html/yourdomain.com >
                    AllowOverride None
                    Order Allow,Deny
                    Allow from All
                    FallbackResource /index.php
                    Options FollowSymLinks MultiViews
            </Directory>
    
            <Directory /var/www/html/yourdomain.com >
                    DirectoryIndex disabled
                    FallbackResource disabled
            </Directory>
    
    
    RewriteEngine on
    
    
    Include /etc/letsencrypt/options-ssl-apache.conf
    #YOUR SSL PEM FİLES
    SSLCertificateFile /etc/letsencrypt/live …..
    SSLCertificateKeyFile /etc/letsencrypt/live …..
    
    
    </VirtualHost>
    </IfModule>
    

    Your caddyfile option should like that

    {
            {$GLOBAL_OPTIONS}
            auto_https off
    }
    
    {$SERVER_NAME::8080}#this parameter will run http://localhost:8080
    

    Mercure command

    MERCURE_PUBLISHER_JWT_KEY='YOUR_KEY' MERCURE_SUBSCRIBER_JWT_KEY='YOUR_KEY' ./mercure run -config Caddyfile
    

    you can try with Caddyfile.dev for test.

    MERCURE_PUBLISHER_JWT_KEY='YOUR_KEY' MERCURE_SUBSCRIBER_JWT_KEY='YOUR_KEY' ./mercure run -config Caddyfile.dev
    

    after this settings your mercure will run yourdomain.com/mercure-hub

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search