【问题标题】:nginx is not redirecting custom ssl port to pm2 appnginx 没有将自定义 ssl 端口重定向到 pm2 应用程序
【发布时间】:2022-08-19 03:06:57
【问题描述】:

我使用 http 协议在单个服务器的不同端口(8000、8200、8300)上运行(通过 pm2)多个 node.js 应用程序。

现在为了启用 https 支持,我安装了 nginx 并编写了配置,用于将端口 8200 上的传入流量重定向到 localhost\ 的端口 8200(同样适用于端口 8000 和 8300),但这会导致 nginx 崩溃并出现错误:nginx: [emerg] bind() to [::]:8200 failed (98: Address already in use)

以下是我的 nginx 配置:

server {
        listen 8200 ssl;
        server_name <redacted>;
        ssl_certificate /certs/<redacted>.cer;
        ssl_certificate_key /certs/<redacted>.key;
        error_page 497 301 =307 https://$host:$server_port$request_uri;
        location / {
            proxy_pass http://localhost:8200;
            proxy_redirect off;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Ssl on;
        }
}

我知道端口 8200 已被 pm2 使用,但我想以某种方式将这些端口上的 http 流量重定向到 https。

    标签: node.js nginx pm2


    【解决方案1】:

    问题是这一行:

    listen 8200 ssl;
    

    您不能在与节点应用程序相同的端口上侦听。

    【讨论】:

      猜你喜欢
      • 2018-04-08
      • 1970-01-01
      • 1970-01-01
      • 2015-09-30
      • 1970-01-01
      • 1970-01-01
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多