0

I have a react application which runs on port 3000. I can access this fine by the IP address and using :3000, however when I try to access the site via the URL, I get the ERR_TOO_MANY_REDIRECTS error.

I've asked the guys who sold me the app, but they tell me the issue is with Cloudflare. The thing is, I don't use cloudflare. I used to some time ago, but my DNS points straight to the server.

I have a single VPS and I only host this one site on it.

The default settings (which I don't know if you will need to help) it the default settings when I installed Nginx.

My current config file for 'rentfromowner' looks like this:

# 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;
}

 }

Can anyone help me understand why it's redirecting and not working because the guys told me this is correct - but I don't think it can be?

Because it's not using port 80 for the app etc - then I have never done anything like this before so I'm trying to learn as much as I can - but I just cant figure it out at all.

Thanks in advance for any help.

P

1 Answer 1

1

In your location / block, once you do the proxy stuff, you should not return 301 ..., that's what is causing the eternal redirect. Just remove that line and let the proxy handle the request.

EDIT:

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

Sorry but which line(s) do I need to remove. Thanks for your help with this Pavel!!!
@Paul added an image to illustrate: simply remove that return 301 ... line, you don't need it there.
@Paul Glad I could help, nginx can be really frustrating sometimes. If my answer solved your problem completely, do you mind accepting it? Cheers ;)
Done ;o) Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.