HTTP request sent, awaiting response... 301 Moved Permanently

Hi,

Tying to get nginx, node and cloudflare to work together. I think everything is fine except that Im getting redirected and a slash is added to the end of the root URL.

Example:
All URLs to the real domain get redirected to https://repick.co// with an extra slash at the end. It can get appended on the same spot also on longer URLs so its not always on the end.

But if I go directly to my public IP it works perfectly after accepting the cert 188.149.51.207

I wonder is this a problem with node, nginx or cloudflare.

Since im not allowed to post more than two links, heres an pastebin with result of WGET and my nginx config:
https://pastebin.com/1HBC90qW

Whats your encryption mode on Cloudflare? Flexible? If so, switch that to “Full strict”.

Its set to strict mode.

So you have set it to “Full strict” and your IP address ends in 207? Correct?

Any page rules in place?

Yes, its set to full strict mode. I also enabled:

Always Use HTTPS
Redirect all requests with scheme “http” to “https”. This applies to all http requests to the zone.

That is correct yes!

Where can I find page rules?

Can you post screenshots of these two pages?

https://dash.cloudflare.com/redirect?zone=dns
https://dash.cloudflare.com/redirect?zone=page-rules

Here the first one:

Second one:

Hmm, that all actually looks all right. I assume you wont have any workers in place either.

I am not sure what that rewrite statement in your server configuration does. Can you comment it out and check if that fixes it?

I tried adding that to remove trailing slashes but it didn’t help. I removed it again now but the same result. That is odd. I have no clue if the problem is within Cloudflare or on my server.

Strange that it works perfectly fine if I go directly to my public IP:
https://188.149.51.207

I do not have any workers in place either, that’s correct.

Do you have access to the server logs?

Just tried adding logs to the http block in my nginx config like this:

error_log  logs/error.log  info;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  logs/access.log  main;

but the logs folder is empty even if I restart nginx and trying accessing the site.

Even if you access the site directly?

That’s a mystery. On my first direct try, it complained about the certificate on the server, but after disabling certificate check, there was no redirect. What certificate do you have on the server?

The site works fine when going directly. It shouldnt be page rules nor workers. Nameservers are also correct, so either it is some obscure issue with Cloudflare or the webserver returns different content to Cloudflare.

1 Like

Hum, very strange. This is the cert I use. I made it under the Origin Server tab in cloudflare

-----BEG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YBBQUHMAGGJGh0dHA6Ly9vY3NwLmNsb3VkZmxhcmUuY29tL29yaWdpbl9j
YTAhBgNVHREEGjAYggsqLnJlcGljay5jb4IJcmVwaWNrLmNvMDgGA1UdHwQxMC8w
LaAroCmGJ2h0dHA6Ly9jcmwuY2xvdWRmbGFyZS5jb20vb3JpZ2luX2NhLmNybDAN
BgkqhkiG9w0BAQsFAAOCAQEAGQ12/t6bvtQWKwu9QuEpmLkNd0yJJR3+kz9x855v
VnTj4/u5wIpGhuNtwi5HIvSUD2ZfzJn4B/FYyBS+dJSwqDKNVjnL3II20P/7eWKj
D1h9KAESDv+GVrMC0/IRT3uloC9j/ulDSuDplGc3c6LvqZ3ooP6xJ+Z/mDsXyqP1
l8R4bGHAis1jSeEFGeTNhkbmJAaswAjWB4pWjzdk9dXgW8rvgLGuK7nA7wX6FyeH
d/iIJETLAt42YhcjLrFLKS/R2Sjq6nJNrmXDFwY+mPgGXrR9yEzQimcWg4q67VIi
HVz80js73UqTPDGlBSCEzPJzMUT4JfuN7qrNhoDkPs4MWA==
-----END CERTIFICATE-----

Can it be a permissions problem on the file in the server?

@nicklas2, though I dont think it would solve it, could you try to purge your entire Cloudflare cache?

Also, what about my log question?

Hum, yep the logs folder is empty even though I access the page directly on the IP.

Tried running both:
sudo nginx -s reload
sudo brew services restart nginx

Its a Mac, therefor its installed via homebrew.

How to I purge cloudflare cache? That would be interesting to try.

Edit:
I managed to get the error logs, they are here:
https://pastebin.com/Y8DGtazf

Not allowed to post more here since its my first day as member. @sandro @sdayman

Edit2:
Heres the access logs also @sandro
https://pastebin.com/KVD11zee

That was me causing the port hangup in the begninning of the logs since I tried just starting nginx again.

Edit3:

Why does it show like:
172.69.68.233 - - [02/Feb/2020:18:19:31 +0100] “GET / HTTP/1.1” 301 5 “http://repick.co” “Mozilla/5.0+(compatible; UptimeRobot/2.0; http://www.uptimerobot.com/)” “69.162.124.234”
172.69.70.13 - - [02/Feb/2020:18:19:32 +0100] “GET // HTTP/1.1” 301 5 “http://repick.co” “Mozilla/5.0+(compatible; UptimeRobot/2.0; http://www.uptimerobot.com/)” “69.162.124.234”

Looks like it is making a get over http that is shouldent? and what does uptimerobot.com has to do with this? :stuck_out_tongue: highly confused…

Edit 4:
@sandro I changed the block in the nginx config to:

server {
  listen 443 ssl; 

  server_name localhost;

  ssl_certificate /usr/local/etc/nginx/repickssl/cert.pem;
  ssl_certificate_key /usr/local/etc/nginx/repickssl/key.pem;

#      location / {
#        proxy_pass http://localhost:3000;
#        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 / {
    root /usr/local/var/www;
  }
}

Now I see the standard nginx page again and dident get redirect issue. it also shows https://repick.co as secure.

However it still adds the extra slash to the end. That is the root cause since the real website will redirect back to repick.co then cloudflare (or whatever it is) will redirect to repick.co// and the loop has started.