带有SSL的Nginx PM2 NodeJS反向代理提供HTTP 504

时间:2018-12-11 17:33:07

标签: node.js ssl nginx socket.io pm2

好的时候,我对在相同的 Ubuntu 16.4 LTS VPS 上运行的三个 NodeJ socket.io API进行了很好的配置>具有 PM2 的服务器,用于进程管理,以及 Nginx ,用于反向代理到三个不同的子域。

我从让我们加密成功安装了 SSL 证书,并且所有子域都来自同一域(例如exemple.com),并且应重定向到https

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

现在,我正在尝试恢复VPS与三个旧NodeJs应用程序的协调,但是它使我从 Nginx 获得了 504网关超时。 / p>

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

此配置在chrome上可以正常使用,但我正尝试从移动和桌面应用程序访问我的API。

import * as Adapter from 'enzyme-adapter-react-16';
enzyme.configure({ adapter: new Adapter() });

更新以获取更多信息。

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

套接字请求成功完成( # 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"; } } wss://

WSS succeed

当其他人请求时失败:

HTTP/S fail

我也想指的是,每个子服务器都安装了SSL,并且应用程序稳定且可以在本地服务器上运行,没有任何问题。

1 个答案:

答案 0 :(得分:1)

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

FF::因此,如果您在此处经过,则可能需要检查您的应用环境。例如:SGBD,R / W权限,API ...

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