【发布时间】:2021-02-04 05:10:57
【问题描述】:
我有一个 NGINX 服务器,当前正在运行一个 ReactJS 应用程序,指向 /build 文件夹,通过 NGINX 启动并运行 HTPPS。
除此之外,我曾经有一个 NodeJS 应用程序(网站)在端口 8888 上运行,并带有一个反向代理,默认情况下可以通过端口 80 访问它。该应用程序以前运行在 HTTP 协议中。
这个 NodeJS 网站在 HTTPS 中提供服务的需求已经上升,我在让这两个应用程序一起运行时遇到了很多麻烦。总是 502 错误或 SLL_do_handshake 错误。
这是我的实际配置。 React 应用程序块未受影响,在我开始修补 Node 之前它运行良好。
server {
listen 80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
# PLATFORM - DEFAULT SERVER
server {
server_name platform.domain.com;
listen 80 default_server;
ssl_certificate /etc/ssl/certs/server.crt;
ssl_certificate_key /etc/ssl/certs/server.key;
location / {
proxy_pass https://xx.xx.xx.xx:8888/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
error_page 404 /404.html;
location = /404.html {}
error_page 500 502 503 504 /50x.html;
location = /50x.html {}
}
# REACT APP
server {
server_name dashboard.domain.com;
listen 443 ssl;
root /var/www/react-app/build;
index index.html;
include snippets/cert-params.conf;
include snippets/ssl-params.conf;
location / {
try_files $uri $uri/ /index.html;
}
}
我的目标是保持其当前功能:2 个独立的应用程序,在同一台机器/网络服务器上,我可以根据用户的需要相互重定向。
我错过了什么?大多数答案让我让 NGINX 处理 HTTPS 部分并让 NodeJS 应用程序在 HTTP 上运行,但我确实需要让 NodeJS 在 HTTPS 上运行。
提前致谢!
【问题讨论】:
标签: node.js nginx nginx-reverse-proxy nginx-config