简体   繁体   English

nginx 未将自定义 ssl 端口重定向到 pm2 应用程序

[英]nginx is not redirecting custom ssl port to pm2 app

I have multiple node.js apps running (through pm2) on different ports (8000, 8200, 8300) of a single server using the http protocol.我有多个 node.js 应用程序在使用 http 协议的单个服务器的不同端口(8000、8200、8300)上运行(通过 pm2)。

Now to enable https support I installed nginx and wrote config for redirecting incoming traffic on port 8200 to the localhost's port 8200 (likewise for ports 8000 and 8300) but it causes nginx to crash with the error: nginx: [emerg] bind() to [::]:8200 failed (98: Address already in use) Now to enable https support I installed nginx and wrote config for redirecting incoming traffic on port 8200 to the localhost's port 8200 (likewise for ports 8000 and 8300) but it causes nginx to crash with the error: nginx: [emerg] bind() to [::]:8200 failed (98: Address already in use)

Following is my nginx config:以下是我的 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;
        }
}

I understand that port 8200 is already being used by pm2 but I want to redirect http traffic on those ports to https somehow.我知道端口 8200 已被 pm2 使用,但我想以某种方式将这些端口上的 http 流量重定向到 https。

The problem is this line:问题是这一行:

listen 8200 ssl;

You can't listen on the same port than your node app.您不能在与节点应用程序相同的端口上侦听。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM