PiTunnel

How to host a HTTP webserver on your Raspberry Pi and access it over the internet

Many projects for Raspberry Pi's often involve running a web server. This can be through, for example:

  • Software you install that has a built-in web server;
  • Your own custom web server that displays status pages for your projects.

In this article we will guide you through how to use PiTunnel to allow you to access a web server running on your Raspberry Pi from anywhere in the world. We will do this by using the Custom Tunnels feature of PiTunnel. All your Raspberry Pi needs is an internet conection and PiTunnel will do the rest.


What is PiTunnel?

PiTunnel is a service for remotely accessing your Raspberry Pi, and the projects that you build on it. A Device Monitor and Remote Terminal is included, and you can also create your own Custom Tunnels to access services running on your Raspberry Pi.


Setting up your web server

If your software already has a web server running, then you are good to go and can proceed to the next step. If you would like to learn how to create your own web server in Python, we recommend looking at the Python Flask framework. Once your web server is running, test that it is accessible on your local network by trying to access it with a web browser from another computer on your network.


Creating a tunnel to access it remotely

Once your web server is running, and it is accessible on your local network, you need to create a custom tunnel so that it can be accessed through pitunnel.com. A tunnel allows you to access your Raspberry Pi web server through PiTunnel.com with either a port (pitunnel.com:12345) or through a subdomain (mytunnel-username.pitunnel.com).

Custom tunnels are created by entering a command in your Raspberry Pi terminal:

pitunnel --port=80 --name=mytunnel --http

Please change the port number in the command above to match the local port number of the web server on your Raspberry Pi.

The Custom Tunnels page contains a helper button "Create Custom Tunnel" to help you form the correct command to create your tunnel. A full explanation of the different command line options is also available in the Command-Line Options section of this documentation.

After you run the command, you will see the following output in your Raspberry Pi terminal:

$ pitunnel --port=80 --name=mytunnel --http
Connected to Tunnel Server pitunnel.com, v1
Waiting for Client connection


Testing your tunnel

To find out the world-wide accessible address for your tunnel, go to the Custom Tunnels page:

Click on the link shown in the "Available At" column to access your web server. A new window will be loaded in your browser with your Raspberry Pi website.


Making your tunnel persistent

Once you have tested that your tunnel works, you will probably want to make it perisistent. This means that the tunnel will load automatically every time your Raspberry Pi powers on, and stay active even if you close the terminal window.

To make a tunnel persistent, add --persist to the end of the command line options:

$ pitunnel --port=80 --name=mytunnel --http --persist
Created Persistent Tunnel

Current Persistent Tunnels:
+----+-------------------------------------------------------+
| ID | Command-Line Arguments                                |
+----+-------------------------------------------------------+
| 1  | --port=80 --name=mytunnel --http                      |
+----+-------------------------------------------------------+

For more information about creating and removing peristent tunnels, please see the Persistent Tunnels section of the documentation.


Next: Access VNC Remote Desktop