reactjs - nginx ssl + react + node,响应超时
问题描述
我制作了一个反应应用程序,它适用于 http 协议。现在我想为这个站点启用 https。我的节点正在侦听端口 5000 并在端口 3000 上做出反应。但是我无法将命令发送到节点正在侦听的端口 5000 并且出现超时错误。这是我在启用站点的文件夹中的 nginx 默认配置文件。
# Default server configuration
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
listen 443 ssl ;
listen [::]:443 ssl ;
root /var/www/html/client/public;
index index.html index.htm index.nginx-debian.html;
server_name www.my_domain.co my_domain.co; # managed by Certbot
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
proxy_pass http://localhost:3000;
}
location /uploads {
proxy_pass http://localhost:5000;
}
location /api {
proxy_pass http://localhost:5000;
}
ssl_certificate /etc/letsencrypt/live/my_domain.co/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/my_domain.co/privkey.pem; # managed by Certbot
}
问题是什么?我很困惑。
解决方案
对于那些遇到类似问题的人。我发现我无法通过 https 将请求发送到某个特定端口(我的是端口 5000),而是使用 nginx proxy-pass 将 /api 的请求发送到 localhost:5000 ,现在我可以正常工作了.
推荐阅读
- javascript - 如何使用 Joi 最新版本验证枚举字符串?
- c++ - 如何将带有浮点数的字符串转换为十进制?
- python - 如何修复点子?pip 无法运行 main 函数
- c# - ASP.NET Core 3.0 中 UPN 的 Active Directory 身份验证
- python - Matplotlib 在 jupyter 和 python 中产生不同的结果
- javascript - React 状态上的映射函数 - 带有获取的 API 数据的状态
- swift - 在 iOS 13.x SDK viewWillDisappear/viewDidDisappear 在 popToRootViewController 操作期间不调用
- c++ - C++ 容器构成的层次结构图
- autodesk-forge - 如何激活 Autodesk Forge Snapper?
- vba - 第二做while循环不执行