首页 > 解决方案 > ERR_TOO_MANY_REDIRECTS Nginx 尝试使用反应应用程序时?

问题描述

我有一个在端口 3000 上运行的反应应用程序。我可以通过 IP 地址和使用:3000 访问它,但是当我尝试通过 URL 访问该站点时,我收到 ERR_TOO_MANY_REDIRECTS 错误。

我问过卖给我应用程序的人,但他们告诉我问题出在 Cloudflare。问题是,我不使用 cloudflare。我以前曾经使用过,但我的 DNS 直接指向服务器。

我有一个 VPS,我只在上面托管这个网站。

默认设置(我不知道您是否需要帮助)它是我安装 Nginx 时的默认设置。

我当前的“rentfromowner”配置文件如下所示:

# the IP(s) on which your node server is running. I chose port 3000.
upstream rentfromowner {
    server 159.65.88.218:3000;
    keepalive 8;
}

# the nginx server instance
server {   
    listen 0.0.0.0:80;
    server_name rentfromowner.co.uk www.rentfromowner.co.uk;
    return 301 https:/rentfromowner.co.uk$request_uri;
}

 server {
    listen 0.0.0.0:443 default_server ssl;
    server_name rentfromowner.co.uk www.rentfromowner.co.uk;
    access_log /var/log/nginx/rentfromowner.log;

    ssl on;
    ssl_certificate /etc/ssl/certs/ssl-bundle.crt;
    ssl_certificate_key /etc/ssl/certs/rentfromowner.co.uk.key;
    ssl_prefer_server_ciphers on;

    # pass the request to the node.js server with the correct headers
    # and much more can be added, see nginx config options
    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://www.rentfromowner.co.uk:3000;
      proxy_redirect off;
      return 301 http://www.rentfromowner.co.uk;
}

 }

谁能帮我理解为什么它会重定向并且不起作用,因为这些人告诉我这是正确的-但我认为不可能吗?

因为它没有将端口 80 用于应用程序等 - 那么我以前从未做过这样的事情,所以我试图尽可能多地学习 - 但我根本无法弄清楚。

提前感谢您的帮助。

标签: reactjsnginx

解决方案


在您的location /区块中,一旦您执行代理操作,您就不应该这样做return 301 ...,这就是导致永久重定向的原因。只需删除该行并让代理处理请求。

编辑:

在此处输入图像描述


推荐阅读