【发布时间】:2019-05-12 18:07:25
【问题描述】:
曾几何时,我为三个 NodeJs、socket.io API 在同一个 Ubuntu 16.4 LTS VPS 上运行了一个很好的配置> 服务器带有 PM2 用于进程管理和 Nginx 用于反向代理到三个不同的子域。
我成功安装了来自 Let's encrypt 的 SSL 证书,并且所有子域都来自同一个域(比如说 exemple.com)并且应该重定向到 https 。
一旦我尝试为非 NodeJs 应用程序 (PHP/laravel) 添加第四个子域,反向代理不再通过,不幸的是我没有旧 Nginx 配置的备份。
现在,我正试图恢复我的 VPS 与三个旧 NodeJs 应用程序的和谐,但它给了我来自 Nginx 的 504 Gateway Time-out。
这是我的配置,我认为是相同的旧配置:
此配置在 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 不会给出任何错误。日志很干净。这是我在检查请求时得到的结果。
socket 请求成功:(wss:// & https://)
别人请求时失败:
我还想指出,每个子系统都安装了 SSL,应用程序稳定且在本地服务器上运行没有任何问题。
【问题讨论】:
标签: node.js ssl nginx socket.io pm2