Cloudflare with websites

I want to setup Cloudflare with a website, run on localhost, There's 2, One's CasaOS and the second one's Crafty Controller, When i tried setting it up it just gave me the error 502
80 Replies
DopeLabs
DopeLabsβ€’15mo ago
the site in cloudflare will need to be configured using some kind of real world reachable ip address... localhost or 127.0.0.1 is not that. you can use a proxy server that listens on the public ip and proxies to your localhost httpd though
Erisa
Erisaβ€’15mo ago
Or implement Cloudflare Tunnel to proxy localhost through an outbound tunnel: https://erisa.dev/exposing-a-web-service-with-cloudflare-tunnel/
MELGEO9
MELGEO9OPβ€’15mo ago
I've managed to access it from outside the server location Cloudflare tunnle is enabled that's what I used Portforwarded using miniupnpc Could you help me do it on Cloudflares web interface? I can @Helpflare
AlphaCentauri
AlphaCentauriβ€’15mo ago
You can follow the instructions here to set up a tunnel using the Cloudflare Dashboard: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/get-started/create-remote-tunnel/
MELGEO9
MELGEO9OPβ€’15mo ago
I've done that but I get error 502 It's not allowing me to get through, And i want to mask the original IP, For the home server so you can't ping it https://casa.srevre.eu.org/
AlphaCentauri
AlphaCentauriβ€’15mo ago
The IP address is not exposed through Cloudflare, so it's already masked per-se. However, if you want to prevent others from accessing it directly, you need to setup a firewall on the server directly, which you can do by following the guidance from the following article (under Configure Origin Server): https://developers.cloudflare.com/fundamentals/setup/allow-cloudflare-ip-addresses/ In terms of the 502 error, have you selected the correct protocol and port on the tunnel? If you curl http://localhost:8080 (or whatever the port is) from the server directly, does it correctly fetch your app?
MELGEO9
MELGEO9OPβ€’15mo ago
The IP address is masked now, And i can access the server with the direct IP, I've selected the protocol http:// and The server is on a system outside my network But I can access it directly
AlphaCentauri
AlphaCentauriβ€’15mo ago
Just to clarify, you have installed Cloudflared on the actual server (outside your network) right?
MELGEO9
MELGEO9OPβ€’15mo ago
Yes It's inside a docker container http://atestforyou.giize.com:132/#/login That's a temp IP for direct access (IP not masked) I can get tunnels to work for minecraft (SRV), that work
AlphaCentauri
AlphaCentauriβ€’15mo ago
For the IP address that you've entered as part of the Tunnel configuration, are you using localhost, or your actual public IP address? And is your app listening on both or just one?
MELGEO9
MELGEO9OPβ€’15mo ago
127.0.0.1 for mc and the website, And the app is listening on port 132 (127.0.0.1:132)
AlphaCentauri
AlphaCentauriβ€’15mo ago
So if you type curl http://127.0.0.1:132 on the terminal on your server, does it spit out the HTML for your website?
MELGEO9
MELGEO9OPβ€’15mo ago
Failed to connect
AlphaCentauri
AlphaCentauriβ€’15mo ago
Perfect, so yeah that's your problem, no app is listening on that IP/port Replace 127.0.0.1 with your public IP Does that work?
MELGEO9
MELGEO9OPβ€’15mo ago
How do i get it to work? as Minecraft also uses that I'll try
AlphaCentauri
AlphaCentauriβ€’15mo ago
You can either bind your app to the loopback interface, or just type your public IP address in the Tunnel configuration. It won't be exposed either way.
MELGEO9
MELGEO9OPβ€’15mo ago
I can't access the server right now https://casa.srevre.eu.org/ HTTP :// (public ip):132
AlphaCentauri
AlphaCentauriβ€’15mo ago
Just so I can try and gauge the setup you have, if you type curl http://publicip:132 on the server, does that connect and display the HTML for your site? We can then ascertain if your app is indeed properly listening on the primary interface on your server and configure the tunnel to use that
MELGEO9
MELGEO9OPβ€’15mo ago
The tunnel is set to :132 and the curl is just stuck on loading
AlphaCentauri
AlphaCentauriβ€’15mo ago
If the cURL command doesn't work, then the tunnel won't work. You mentioned earlier that you could connect to the server directly? I'm assuming that doesn't work either?
MELGEO9
MELGEO9OPβ€’15mo ago
I can't curl that either even though i can access it http://atestforyou.giize.com:132 (direct) https://casa.srevre.eu.org/ (cloudflare) curl: (28) Failed to connect to <IP> port 132 after 129618 ms: Connection timed out is that ping? as the router has ping disabled
AlphaCentauri
AlphaCentauriβ€’15mo ago
No that's not ping, you can block ICMP (ping) requests fine, the cURL command just makes a HTTP request which needs to work
MELGEO9
MELGEO9OPβ€’15mo ago
The curl command doesnt work with the d-dns either, that I can access
AlphaCentauri
AlphaCentauriβ€’15mo ago
Alright the cURL command works for me (I can access everything just fine directly to your IP), so that's super odd. Just to confirm one more time, if you type "curl http://atestforyou.giize.com:132/" on the server that hosts your app, that times out?
MELGEO9
MELGEO9OPβ€’15mo ago
It's timinng out for me, inside the home network The server is not on my network, I'm using curl from ssh
AlphaCentauri
AlphaCentauriβ€’15mo ago
Yep, so you're using cURL whilst logged into the actual server where your app/website is hosted and that fails?
MELGEO9
MELGEO9OPβ€’15mo ago
yes I can use curl from CMD, I just can't use it the same inside the server
AlphaCentauri
AlphaCentauriβ€’15mo ago
Yeah that's the behavior on my end too, I can access your IP from my network, so I would assume you can also do the same from your home network right? It's just the server that cannot access its own app? Have you setup any odd firewall rules? If so, remove them and then we can get your site working, and then add the necessary rules back
MELGEO9
MELGEO9OPβ€’15mo ago
The server has no extra firewalls I can disable the network firewalls temporary though
AlphaCentauri
AlphaCentauriβ€’15mo ago
Try that, if you cannot cURL your own app from inside the server that is hosting it, a Cloudflare Tunnel will never work
MELGEO9
MELGEO9OPβ€’15mo ago
Tunnels work with my mc servers, But not the webui for casaos/webui for mc serves firewalls are disabled now, still can't access it
AlphaCentauri
AlphaCentauriβ€’15mo ago
Even the previous cURL command while SSH'd into the server itself?
MELGEO9
MELGEO9OPβ€’15mo ago
curl still doesn't work while ssh'd
AlphaCentauri
AlphaCentauriβ€’15mo ago
Wait, are you doing some sort of port forwarding? Is the native port of this app 132?
MELGEO9
MELGEO9OPβ€’15mo ago
the port inside the app is 80 the port outside is 132 upnpc -a (local ip) 80 132 tcp the router gives me an error when i try port 80
AlphaCentauri
AlphaCentauriβ€’15mo ago
Can you retry that cURL command whilst SSHd into the server but use port 80 instead of 132? What is listening on port 80 You shouldn't have to port forward when dealing with Tunnels, it eradicates the need to do any of that
MELGEO9
MELGEO9OPβ€’15mo ago
It curl's, just no output should i tunnel port 80?
AlphaCentauri
AlphaCentauriβ€’15mo ago
Okay yeah this makes sense now, it sounds like something is listening on port 80, so in your Tunnel configuaration, use port 80 and not 132 If that doesn't work (and port 80 is taken by something else), you need to change the actual listening port of casaos to something else and use that within the Tunnel config.
AlphaCentauri
AlphaCentauriβ€’15mo ago
I googled your particular app, try logging in and changing the port to something like 8081 or something that is unused
No description
MELGEO9
MELGEO9OPβ€’15mo ago
I can't seem to access the webui anymore
AlphaCentauri
AlphaCentauriβ€’15mo ago
What did you change on your server?
MELGEO9
MELGEO9OPβ€’15mo ago
the webui port
AlphaCentauri
AlphaCentauriβ€’15mo ago
To what?
MELGEO9
MELGEO9OPβ€’15mo ago
give me a few mins i need to deal with something
AlphaCentauri
AlphaCentauriβ€’15mo ago
Sure
MELGEO9
MELGEO9OPβ€’15mo ago
I've managed to get back into casaos using the direct IP still nothing on cloudflares side though
AlphaCentauri
AlphaCentauriβ€’15mo ago
Without knowing the specific setup you have, the issue here is definitely related to the fact that the Tunnel needs to point to the IP and port that the app is bound to, but your port forwarding is causing issues with this, hence the cURL failures directly on the server which should never happen. Is that IP (ending in .6) the IP address of the server itself, or is that on your home network?
MELGEO9
MELGEO9OPβ€’15mo ago
that's the server IP
AlphaCentauri
AlphaCentauriβ€’15mo ago
And when you login to the Web UI, what port is CasaOS listening on? I'm assuming it says 80 and not 132 when you login?
MELGEO9
MELGEO9OPβ€’15mo ago
I set casa to 132 and the public to 132
AlphaCentauri
AlphaCentauriβ€’15mo ago
Ah okay, but did you change it from another value?
MELGEO9
MELGEO9OPβ€’15mo ago
I changed casa from port 80 to 132
AlphaCentauri
AlphaCentauriβ€’15mo ago
Okay perfect, so try that old cURL command whilst SSHd into the server once more "curl http://atestforyou.giize.com:132/" Now that it's listening on that port, it should work
MELGEO9
MELGEO9OPβ€’15mo ago
It still isn't giving me a response from the terminal Its just blank Is that relate to my docker containers?
AlphaCentauri
AlphaCentauriβ€’15mo ago
CasaOS is not installed via Docker right?
MELGEO9
MELGEO9OPβ€’15mo ago
No
AlphaCentauri
AlphaCentauriβ€’15mo ago
Then it won't be an issue (unless you're using that port for a Docker container) To get this working your own server needs to be able to access the app, the fact that this isn't happening indicates a configuration issue somewhere. Can you try one last thing. Can you change the port from the Web UI from 132 to another unused port that you're also NOT using in any port forwarding configuration or other app. And then can you try accessing the WebUI either directly or via cURL with that new unused port Something definitely unused like 8084
MELGEO9
MELGEO9OPβ€’15mo ago
I changed it too 174, And it still deosn't work changed the cloudflare config also and https://atestforyou.giize.com:8111/ hass the same issue (crafty controller)
AlphaCentauri
AlphaCentauriβ€’15mo ago
Yeah this won't be a Cloudflare issue, there's something wrong with the configuration on your server which is hard to troubleshoot because I/we can't really see anything. I just setup a random CasaOS install on a VM I spun up and it worked perfectly with a tunnel, so I can only guess there's something else you've installed or done which we can't see 😬
MELGEO9
MELGEO9OPβ€’15mo ago
Okay,thanks
AlphaCentauri
AlphaCentauriβ€’15mo ago
No worries, hope you get it sorted, tinkering always ends up working in the end πŸ˜„
MELGEO9
MELGEO9OPβ€’15mo ago
I've gotton a question, @AlphaCentauri , What did you input as your cloudflare config from zero dash?
AlphaCentauri
AlphaCentauriβ€’15mo ago
I set the protocol to HTTP, the IP address to my VMs primary IP, and the port to 80, which was the standard port it used.
MELGEO9
MELGEO9OPβ€’15mo ago
Does it look similar to this?
No description
AlphaCentauri
AlphaCentauriβ€’15mo ago
I used a trycloudflare.com tunnel though as it was purely a test, so I didn’t use the zero trust dashboard, but yes, it’d look exactly like that.
MELGEO9
MELGEO9OPβ€’15mo ago
I just changed it from http to https and now the dashboard seems to work from casa.srevre.eu.org
AlphaCentauri
AlphaCentauriβ€’15mo ago
Oh perfect, glad you got it working πŸŽ‰
MELGEO9
MELGEO9OPβ€’15mo ago
Yeah, Now just time to figure it out with the crafty controller, as that ones still giving me the error
MELGEO9
MELGEO9OPβ€’15mo ago
Yes, It is
AlphaCentauri
AlphaCentauriβ€’15mo ago
That's using a self signed SSL certificate, so select HTTPS as the protocol, and make sure to go into TLS Settings and enable the option for No TLS Verify
No description
AlphaCentauri
AlphaCentauriβ€’15mo ago
The better option is to use a real signed SSL certificate like Letsencrypt or a Cloudflare Origin SSL certificate which are both free, but the above option should also work
MELGEO9
MELGEO9OPβ€’15mo ago
Thank you, It works now
AlphaCentauri
AlphaCentauriβ€’15mo ago
Amazing, glad to hear it πŸŽ‰
MELGEO9
MELGEO9OPβ€’15mo ago
And how do i get a cloudflare certificate?
MELGEO9
MELGEO9OPβ€’15mo ago
Thank you so much man
AlphaCentauri
AlphaCentauriβ€’15mo ago
No worries, happy to help! We got there in the end πŸ˜„
MELGEO9
MELGEO9OPβ€’15mo ago
Yeah, Thanks! @AlphaCentauri Could you check your DM's please?
AlphaCentauri
AlphaCentauriβ€’15mo ago
Sure thing

Did you find this page helpful?