Hosting Website on Phone

4 hours ago 1

If you follow this blog, you must have come across my previous post that talked about how every phone should be able to host personal website. Well in this post I’m doing exactly that. If you haven’t read that post, please do.

Hosting a website is not that hard. Anyone with Linux server could do it in few key strokes but it’s not that easy on phone. Modern phone operating systems have locked down the phones to a point that anything like hosting website feels like a wild idea.

The Problem

On Android, no application can bind on port below 10241. It basically means even if you start a webserver on your phone the remote browser will have to specify the port number of your server along with url of your server. It will work but I think you will agree that it does not have the same feel to it. The website should be accessible just by it’s domain name.

You can solve the port issue by adding another device like Raspberry Pi in front of your phone which can act as reverse proxy but then why would you not host on the Pi itself. Also your web server would not be truly mobile in that case. Another approach would be to root your phone but again that is too much of hassle for hosting a simple website.

For a long time, there was no real solution to this problem. I even complained about the port binding issue to Android development team to no avail. But finally it’s possible. Enters DNS HTTPS records.

DNS HTTPS Records

What are HTTPS Records?

HTTPS-records allows browsers to efficiently obtain complete instructions for accessing a web-site for a domain name - including supported protocols (HTTP/1.1, 2, 3, etc.), ip address(es), port number, and public keys (all optional) - saving the browser from doing a number of DNS lookups and other protocol negotiation steps.

Theres lot you can do with HTTPS records but we are interested in its ability to specify port number in the DNS record itself. The client browser will connect directly on that port. This basically allows us to run web server on any port above 1024 without having to worry about sharing the port information. Users will be able to access your phone site just by domain name! I have tested it with Cloudflare and it works like charm. Below screenshot shows how we can define the HTTPS records for a domain on Cloudflare.

So there you have it. A way to run fully functional web server on a phone. What will you do with it?

Read Entire Article