首页 > 解决方案 > 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 很陌生。我不知道我在哪里搞砸了。感谢您的帮助

标签: node.jsamazon-web-servicesnginxcloudflare

解决方案


推荐阅读