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


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.

All URLs to the real domain get redirected to 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

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:

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?

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:

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


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.

I managed to get the error logs, they are here:

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

Heres the access logs also @sandro

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


Why does it show like: - - [02/Feb/2020:18:19:31 +0100] “GET / HTTP/1.1” 301 5 “” “Mozilla/5.0+(compatible; UptimeRobot/2.0;” “” - - [02/Feb/2020:18:19:32 +0100] “GET // HTTP/1.1” 301 5 “” “Mozilla/5.0+(compatible; UptimeRobot/2.0;” “”

Looks like it is making a get over http that is shouldent? and what does 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 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 then cloudflare (or whatever it is) will redirect to and the loop has started.