【发布时间】: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。