Friday 30 March 2018

Host a Website using RaspberryPi

Host a website from your Pi

Host websites, control panels and device APIs at <yourdevice>.dataplicity.io
Dataplicity Wormhole allows you to host a website from your Raspberry Pi, regardless of where it is installed, at a specific address (https://<yourdevice>.dataplicity.io/). Port forwarding, firewall exceptions and Dynamic DNS are no longer required. See how it works here.

Pre-requisites

For Wormhole you will need:

Make sure to free up port 80

If you have been going through other tutorials for wormhole you might have an application or a service already running on port 80. Make sure that nothing is running on port 80 prior to following the instructions in this article.

Install a web server on your Pi

If you already have a web service running on your Pi which is listening on localhost port 80, you can skip this section. Otherwise, you'll need to install one. In this example we're going to install a very popular web server called NGINX (pronounced "Engine-X" - any other web server will do).
Type the following into your Pi terminal:
sudo apt-get install nginx
NGINX will usually start by itself, but you should verify that the web server is running:
sudo netstat -an | grep LISTEN | grep :80
The output should indicate that something is listening on port 80:
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN
tcp6       0      0 :::80                   :::*                    LISTEN
If you aren't seeing the output above, check your web service is running properly, and perhaps try restarting it:
sudo service nginx restart

Enabling Wormhole

To enable Wormhole, log in to your Dataplicity account. You'll want to do this on a laptop. Open up the Device page for your Pi.
You should see a button next to the device name that says "Activate Wormhole":
Click "Activate Wormhole".
If you do not see the "Activate Wormhole" button, check to ensure that you have your Pi connected to the internet and you've correctly updated the Dataplicity client to a recent version. If you have issues, you may re-try the Dataplicity agent installation.
When pressed, the button will be replaced with a direct link to your device, like so:
The green text is a clickable link to the web site on your Pi
The green text is a clickable link to the web site on your Pi
Click the link (or type it into your browser). You should see your device website.
The website above is actually running on your Pi. The files for it, and the code for it, are all in the Pi. And if you remove your Pi from your home network and take it to a hackathon, the website link is still the same!
Awesome :-)

Security considerations

When you switch on Wormhole you are placing the web service hosted on your Pi directly on the wider internet. That's actually the point, but what it means is that you need to take special care in what you put online.
In this case, NGINX is running on port 80 directly from your Pi. Wormhole listens only on localhost, so you don't need to have port 80 open directly from your Pi to the wider world - even though this is not inherently insecure.
Just to avoid confusion it's sensible to close the device port by installing a firewall. Depending on your application you may also wish to enable HTTP basic-authentication from the NGINX configuration, and require a password for website access.
We've put together some basic tips for Securing Wormhole - well worth a read

No comments:

Post a Comment

How to install google-chrome in redhat without redhat subscription

Install google-chrome in redhat  Download the .rpm file of chrome https://www.google.com/chrome/thank-you.html?installdataindex=empty&st...