Mercure keeps binding to port 80

784 Views Asked by At

I'm using the Mercure hub 0.13, everything works fine on my development machine, but on my test server the hub keeps on trying to bind on port 80, resulting in a error, as nginx is already running on port 80.

run: loading initial config: loading new config: http app module: start: tcp: listening on :80: listen tcp :80: bind: address already in use

I'm starting the hub with the following command:

MERCURE_PUBLISHER_JWT_KEY=$(cat publisher.key.pub) \
MERCURE_PUBLISHER_JWT_ALG=RS256 \
MERCURE_SUBSCRIBER_JWT_KEY=$(cat publisher.key.pub) \
MERCURE_SUBSCRIBER_JWT_ALG=RS256 \
./mercure run -config Caddyfile.dev

Caddyfile.dev is as follows:

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

{$SERVER_NAME:localhost:3000}

log

route {
        redir / /.well-known/mercure/ui/
        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}
                # Permissive configuration for the development environment
                cors_origins *
                publish_origins *
                demo
                anonymous
                subscriptions
                # Extra directives
                {$MERCURE_EXTRA_DIRECTIVES}
        }

        respond /healthz 200

        respond "Not Found" 404
}

When I provider the SERVER_NAME as an environment variable, without a domain, SERVER_NAME=:3000, the hub actually starts on port 3000, but runs in http mode, which only allows for anonymous subscriptions and is not what I need.

Server:

Operating System: CentOS Stream 8
Kernel: Linux 4.18.0-383.el8.x86_64
Architecture: x86-64

Full output when trying to start the Mercure hub:

2022/05/10 04:50:29.605 INFO    using provided configuration    {"config_file": "Caddyfile.dev", "config_adapter": ""}
2022/05/10 04:50:29.606 WARN    input is not formatted with 'caddy fmt' {"adapter": "caddyfile", "file": "Caddyfile.dev", "line": 3}
2022/05/10 04:50:29.609 INFO    admin   admin endpoint started  {"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["localhost:2019", "[::1]:2019", "127.0.0.1:2019"]}
2022/05/10 04:50:29.610 INFO    http    enabling automatic HTTP->HTTPS redirects    {"server_name": "srv0"}
2022/05/10 04:50:29.610 INFO    tls.cache.maintenance   started background certificate maintenance  {"cache": "0xc0003d6150"}
2022/05/10 04:50:29.627 INFO    tls cleaning storage unit   {"description": "FileStorage:/root/.local/share/caddy"}
2022/05/10 04:50:29.628 INFO    tls finished cleaning storage units
2022/05/10 04:50:29.642 INFO    pki.ca.local    root certificate is already trusted by system   {"path": "storage:pki/authorities/local/root.crt"}
2022/05/10 04:50:29.643 INFO    tls.cache.maintenance   stopped background certificate maintenance  {"cache": "0xc0003d6150"}
run: loading initial config: loading new config: http app module: start: tcp: listening on :80: listen tcp :80: bind: address already in use
1

There are 1 best solutions below

1
On

I'm a bit late, but I hope that will help someone.

As mentionned here, you can specify the http_port manually in your caddy configuration file.