如何在生产中运行 Mercure [英] How to run Mercure in production

查看:95
本文介绍了如何在生产中运行 Mercure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在生产环境中的 Symfony 上运行 Mercure.

I'm trying to run Mercure on Symfony within a production env.

[第一个问题]

似乎我需要保持 ssh 连接处于活动状态才能保持 mercure 运行.
另外,我希望能够运行多个 Mercure 实例(每个虚拟主机一个)

It seems that I need to keep my ssh connection active in order to keep mercure running.
Also, I would like to be able to run multiple instance of Mercure (one per vhost)

[第二个问题]

由于我的虚拟主机已经在使用 HTTPS,我使用以下命令运行 Mercure:

As my vhost is already using HTTPS, I'm using the following command to run Mercure:

JWT_KEY='4e2da03eda9acdfdb9253ab0f8f9e4011706fd6ba6d8293d9727e833752fb15b' CERT_FILE='/etc/letsencrypt/live/my-project.my-domain.com/fullchain.pem' KEY_FILE='/etc/letsencrypt/live/my-project.my-domain.com/privkey.pem' ALLOW_ANONYMOUS=1 ./mercure/mercure

如果我用我的网络用户 (www-data) 尝试这个命令,我会收到以下错误:

If I try this command with my web user (www-data), I get the following error:

ERRO[0000] 监听 tcp :443: 绑定:权限被拒绝

ERRO[0000] listen tcp :443: bind: permission denied

如果我尝试用 root 运行它,我会得到这个错误:

If I try to run it with root, I get this error instead:

ERRO[0000] listen tcp :443: bind: address already in use

ERRO[0000] listen tcp :443: bind: address already in use

网络上的一些消息建议使用代理,但没有提供任何示例.

Some messages here and there on the web suggested to use a proxy, but don't provide any example.

有人可以提供一个解决方案,首先运行 Mercure 而不需要在 ssh 上保持我的用户连接,并且如果可能的话,能够为每个项目 (vhost) 运行一个 mercure 实例(mercure 在我的项目的根目录下))

Can someone provide a solution to, first, run Mercure without having to keep my user connection on ssh, and if possible, being able to run one instance of mercure per project (vhost) (mercure is at the root of my project)

第二,提供一个完整的例子以及如何解决端口问题或如何使用代理的问题.

Second, provide a full example and how to solve the problem of either, ports issue or how to use a proxy.

推荐答案

  1. 您可以使用 nohup 命令,例如 JWT_KEY='[key]' nohup ./mercure/mercure &

正确的方法是使用 supervisord 来管理这个过程,因为你想在服务器启动时自动运行 mercure

The right way would be to use supervisord to manage this process as you want to automatically run mercure at the server start

有一个用于此的 ADDR 环境,例如JWT_KEY='[key]' ADDR=127.0.0.1:3000 ./mercure/mercure 会监听 127.0.0.1:3000 地址.您需要在每个项目的不同端口上运行多个 mercure 实例.

There is an ADDR env for this, e.g. JWT_KEY='[key]' ADDR=127.0.0.1:3000 ./mercure/mercure will listen 127.0.0.1:3000 address. You need to run multiple instances of mercure on different ports for each of your project.

您可以使用 nginx 代理 像这样:

You could use nginx proxy something like this:

server {
    listen 80 ssl http2;
    listen [::]:80 ssl http2;
    server_name project1.exmaple.com;

    ssl_certificate /path/to/ssl/cert.crt;
    ssl_certificate_key /path/to/ssl/cert.key;

    location / {
        proxy_pass http://127.0.0.1:3001;
        proxy_read_timeout 24h;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }
}

server {
    listen 80 ssl http2;
    listen [::]:80 ssl http2;
    server_name project2.exmaple.com;

    ssl_certificate /path/to/ssl/cert.crt;
    ssl_certificate_key /path/to/ssl/cert.key;

    location / {
        proxy_pass http://127.0.0.1:3002;
        proxy_read_timeout 24h;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }
}

端口<代码><1024 只能被root用户绑定.这就是为什么你有 permission denied 错误,对于 www-data 用户

Ports < 1024 can be bound only by root user. That's why you've got permission denied error, for www-data user

这篇关于如何在生产中运行 Mercure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆