node.js - HTTPS 与 Nginx 和 Nodejs
问题描述
所以我使用 certbot 为 https 配置 Nginx。效果很好(我使用了自动配置)。
现在如何配置我的 Node.js 后端,以便能够从 Nginx 托管的前端发出 GET/POST 请求?
编辑:
location /api {
proxy_pass http://localhost:3000; #server port
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;
}
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
解决方案
如果您已使用 Ssl 和节点应用程序正确配置了 Nginx。您发送的请求应与https://URL一起使用。请检查您的 nginx.conf 并验证以下内容。
您可以在 Nginx 中添加 ssl 证书
ssl_certificate /etc/nginx/ssl/server.crt #cert location
ssl_certificate_key /etc/nginx/ssl/server.key #key location
在 Nginx 的服务器块中。并且您的 nodejs 应用程序应该在服务器块中这样配置
location / {
proxy_pass http://localhost:3000; #server port
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;
}
这足以让您的服务器使用 SSL。
推荐阅读
- google-apps-script - 如何修复:对 gmail.users.settings.filters.create 的 API 调用失败并出现错误:空响应
- ckeditor - 在 CKEditor 源模式下启用复制粘贴选项
- javascript - 如何在 JavaScript 中使这个异步查询同步?
- r - 一些来自矩阵的输入和其他来自向量的输入,如何替换二维循环?
- go - 将值附加到 Golang 中结构的结构返回无效的内存地址
- python - 检查和删除两个不对称数据帧的最快方法是什么
- javascript - 是什么导致“您确定要离开此页面”在 iframe/网页中?
- android - Android 错误:Firebase 数据库组件不存在
- python - 如何从火花数据框中提取 csv 名称
- outlook - Outlook 中的对话/线程/帖子有什么区别?