node.js - Cloudflare 重复重定向错误(Node JS 应用程序、NGINX 用于反向代理、Amazon EC2、SSL)
问题描述
我有一个节点应用程序在 Amazon EC2 服务器上的端口 3000 上运行,NGINX 反向代理在同一服务器实例上运行,Cloudflare 是我的 DNS。我正在尝试通过端口 80(http) 和端口 443(https) 将域名附加到节点应用程序
在 Nginx 配置文件中,如果我在端口 80 上监听,一切正常。以下是配置文件(这没问题,因为我正在监听端口 80):
server {
listen 80;
server_name example.in;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:3000;
}
}
但如果尝试在 443 上收听,我会收到 ERR_TOO_MANY_REDIRECTS。
这是配置文件:(我使用 Cloudflare 提供的私钥和公钥)
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name example.in;
ssl_certificate /etc/nginx/certs/cloudflare.pem;
ssl_certificate_key /etc/nginx/certs/cloudflare.key;
ssl on;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/nginx.vhost.access.log;
location / {
proxy_set_header Host $host;
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_pass http://localhost:3000;
proxy_read_timeout 90;
proxy_redirect http://localhost:3000 https://example.in;
}
}
我跟着这个链接 我对 Nginx 和 Cloudflare 很陌生。我不知道我在哪里搞砸了。感谢您的帮助
解决方案
推荐阅读
- maven - 运行 maven surefire 测试插件 Java 11 时出错
- c# - 使用c#将xml元素提取到字符串中
- jpa - JPA - 使用 EntityManager remove() 方法的奇怪行为
- c++ - 从向量中读取和排序的文件中的负输出值
- python-3.x - YOLO v3 的 OpenCV 实现在 GCP 实例上重现异常
- api - Kubernetes API 服务器支持哪些数据格式?
- java - 休眠搜索不从远程 Windows 服务器数据库索引
- javascript - Dropdown not being populated from HTTP response
- gitlab - 从 GitLab 工件存档下载单个文件
- javascript - 纯 JS 中的语言识别(en/ger) - 需要改进