I have a server that serves multiple websites, the server is behind the NAT, so I set port forwarder on the gateway. It works fine till I set up Cloudflare and proxy the DNS records for this public IP.
I’m not sure how to address this issue, anyone can share a light?
NAT is usually used to forward TCP/UDP packets, while HTTP is built on top of TCP, it is likely going to give issues especially if SSL is used.
If you need to forward HTTP connections use proper software such as NGINX or HAPROXY.
Yeah, that should work. If the public IP is IPv4, do you have firewall, port forwarding and DNS entry in Cloudflare all to that IP (and the same if it’s IPv6)? No rate limits, or blocks? The public port 80 goes to the HTTP port at the web server and port 443 goes to the HTTPS port? Do you have redirects from one to the other in the web server? What error does Cloudflare show?
The page isn’t redirecting properly
An error occurred during a connection to xxx.com
This problem can sometimes be caused by disabling or refusing to accept cookies.
The firewall rule on the server is empty. Server is using vaild SSL cert.
Both 443 and 80 are standard ports, so no port forwarding is needed on Cloudflare I believe.
It’s pretty helpful to use a command line curl -I https://example.com (your domain) and watch the redirects to see why. It’ll show you a 301, then a “Location” so I try another curl with the new location, and so on until I see what the redirect loop is.
That was quite informative. It redirects to itself, but with a slash at the end. So now you need to curl -I to the what it says in the “location” header (which has a slash at the end).
With that out of the way, I am pretty sure your domain is redirecting to HTTPS, which will never work as you are technically already on HTTPS. Can you try setting Full and, ideally if you have (or can get) a valid certificate on the server, Full (Strict)? Redirects on the server should be mostly disabled with Cloudflare.
The problem has been fixed. I installed valid SSL on the server side and rebooted the web service, then enabled Full on Cloudflare.
Thank you all for the help.