0

我正在与您联系,因为我无法让mercure从事生产工作。

二进制预构建运行良好,但是当我尝试连接到集线器时,我得到 404 no found。

这是我运行的命令:

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

服务器启动显然没有任何问题:

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

我的 .env 配置如下:

###> 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 ###

我的球童文件:

# 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
}

当我尝试通过键入以下命令使用邮递员访问集线器时:

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

我得到一个 404 找不到。

我在带有 apache2 的 linux debian 10 下。我不明白我做错了什么。谢谢你的帮助。

编辑 21/02/2022

嗨,Mehmet,这是我所做的:

在 /etc/apache2/sites-available monsite.conf 和 monsite-le-ssl.conf :

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

在 Caddyfile 和 Caddyfile.dev :

{
        {$GLOBAL_OPTIONS}
        auto_https off }

{$SERVER_NAME::8080}

显然集线器启动良好,我在控制台中没有错误:

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

无论我运行 Caddyfile 还是 Caddyfile.dev,在访问https://monsite.com/mercure-hub时,都会收到 500 错误。

4

2 回答 2

0

那是我的apache设置。也许对你有帮助。

打开纳米 /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>

您的 caddyfile 选项应该是这样的

{
        {$GLOBAL_OPTIONS}
        auto_https off
}

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

美居指挥部

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

您可以尝试使用 Caddyfile.dev 进行测试。

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

完成此设置后,您的 Mercure 将运行 yourdomain.com/mercure-hub

于 2022-02-20T11:26:43.720 回答
0

经过一番挖掘,我试图弄清楚为什么它会返回 500 错误。我去了 apache 日志,我收到了这个错误消息:

“没有协议处理程序对 URL / 有效。如果您使用的是 mod_proxy 的 DSO 版本,请确保代理子模块包含在使用 LoadModule 的配置中”

所以我安装了缺少的组件:

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

我还通过在 mercure-hub 末尾添加斜杠修改了代理 url,否则我会收到 404 错误:

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

重新启动 apache,并更新了我的 .env 中的 Url:

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

它有效,非常感谢!

于 2022-02-21T15:19:57.153 回答