gpt4 book ai didi

node.js - 带 SSL 的 Nginx PM2 NodeJS 反向代理提供 HTTP 504

转载 作者:太空宇宙 更新时间:2023-11-03 14:00:12 26 4
gpt4 key购买 nike

曾几何时,我为三个 NodeJsocket.io API 运行在同一个 Ubuntu 16.4 LTS VPS 上做了一个很好的配置> 服务器带有用于进程管理的 PM2 和用于反向代理到三个不同子域的 Nginx

我成功安装了来自 Let's encryptSSL 证书,所有子域都来自同一个域(比方说 exemple.com),应该重定向到 https .

一旦我尝试为非 NodeJs 应用程序 (PHP/laravel) 添加第四个子域,反向代理就不再通过,不幸的是我没有旧 Nginx 配置的备份。

现在,我正试图恢复我的 VPS 与三个旧的 NodeJs 应用程序的和谐,但它让我从 Nginx504 网关超时

这是我认为与旧配置相同的配置:

此配置在 chrome 上运行良好,但我正在尝试从移动和桌面应用程序访问我的 API。

  # HTTP — redirect all traffic to HTTPS
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
return 301 https://$host$request_uri;
}

# App1 from port 3000 to sub1.exemple.com
server {
# Enable HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name sub1.exemple.com;

# Use the Let’s Encrypt certificates
ssl_certificate
/etc/letsencrypt/live/sub1.exemple.com/fullchain.pem;
ssl_certificate_key
/etc/letsencrypt/live/sub1.exemple.com/privkey.pem;

# Include the SSL configuration from cipherli.st
include snippets/ssl-params.conf;

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;

proxy_pass http://localhost:3000/;
proxy_redirect off;

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

# App2 from port 4000 to sub2.exemple.com
server {
# Enable HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name sub2.exemple.com;

# Use the Let’s Encrypt certificates
ssl_certificate
/etc/letsencrypt/live/sub2.exemple.com/fullchain.pem;
ssl_certificate_key
/etc/letsencrypt/live/sub2.exemple.com/privkey.pem;

# Include the SSL configuration from cipherli.st
include snippets/ssl-params.conf;

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;

proxy_pass http://localhost:4000/;
proxy_redirect off;

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

# App2 from port 5000 to sub3.exemple.com
server {
# Enable HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name sub3.exemple.com;

# Use the Let’s Encrypt certificates
ssl_certificate
/etc/letsencrypt/live/sub3.exemple.com/fullchain.pem;
ssl_certificate_key
/etc/letsencrypt/live/sub3.exemple.com/privkey.pem;

# Include the SSL configuration from cipherli.st
include snippets/ssl-params.conf;

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;

proxy_pass http://localhost:5000/;
proxy_redirect off;

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

更新以获取更多信息。

Nginx、NodeJs 和 PM2 没有给出任何错误。日志是干净的。这是我在检查请求时得到的。

套接字请求成功:(wss:// & https://)

WSS succeed

其他人请求时失败:

HTTP/S fail

我还想指出,每个 sub 都安装了 SSL,应用程序稳定并在本地服务器上运行没有任何问题。

最佳答案

我发现了问题,它不在不是 Nginx不是 PM2不是 Nodejs 也不在 SSL,这都在我部署的应用程序中。 Mongodb 的进程 中的一个问题使他不自动启动。因此,应用程序接受第一个请求,因为它不需要数据库干预,并在超时后拒绝登录请求,因为应用程序已经崩溃但 PM2 重新启动它并且 Nginx 保持子域对请求开放。

FF: 因此,如果您路过这里,您可能需要检查您的应用环境。例如:SGBD、R/W 权限、API...

希望这可以帮助任何遇到类似问题的人。

关于node.js - 带 SSL 的 Nginx PM2 NodeJS 反向代理提供 HTTP 504,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53729419/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com