I'm running Ubuntu mate on my raspberry pi 2 b+ . I want to make it hosting an HTMl file. My problem is that I'm low on ressources. E.g. with my main usage program which runs 24/7 on it, there's no memory left for starting Firefox, so I need a lightweight solution. I don't need a complex site, just something that returns this sample.html file if someone accesses http://192.168.178.8 (as sample)
3 Answers
I take it, that you really just want to read an HTML document on the Raspi, but the system has not enough memory to start its default browser Firefox.
You could try a more lightweight browser like midori
. Install with
sudo apt-get install midori
If you truly need to serve the pages to the local LAN, you need to install a web-server.
nginx
is resource-wise a good choice.
Install it with
sudo apt-get install nginx-light nginx-common
There is also a
nginx-full
package which brings more functionality, but I don't believe is needed here.When the installation is done, the server should start automatically. You can control it with
sudo service nginx start/stop/restart/...
If you now browse to the address of the Raspi, you will already see a page being served ("Welcome to nginx...")
The welcome page you see is served from
/var/www/html
. The configuration is stored in/etc/nginx
.If you are lazy and want a quick fix, simply put your files into this folder. By default a document
index.html
is served. If it does not exist, a document tree will be served instead. The directory contains of course the welcome-page. Move it out of the way first. If you want to serve files from a different folder, read on.There exist two directories
/etc/nginx/sites-available /etc/nginx/sites-enabled
The first one holds the actual configuration files, while the second contains links to those configuration sites. These links tell nginx to process the config and serve the site.
For your goal it suffices to adapt the existing configuration a bit.
First, delete the symlink to
default
sudo rm /etc/nginx/sites-enabled/default
so the server will not serve the Welcome page by default.
Now copy
default
and alter itcd /etc/nginx/sites-available sudo cp default mysite
Name it anyway you like better than
mysite
.Open the file with an editor. Most of the setting are fine, but you need to adapt
root
so it points to the directory which contains the files you want to serve. This is basically all you need to do, but one option is quite useful:index
: Which document is served when the document root http://server/ is browsed.Reload the config with
sudo service nginx reload
and your Pi should serve your webpage!
nginx is a lightweight web server, runs well on Raspi
sudo apt-get -y install nginx
Place your default page under /var/www/html
To configure edit /etc/nginx/nginx.conf
Install package netcat-openbsd
. With that the following shell script gets you a very simplistic web server that just always returns your sample.html
for any request.
Note that it can't provide any additional files like images, CSS files or similar.
#!/bin/sh
while (
printf "HTTP/1.1 200 OK\r\n"
printf "Content-Type: text/html\r\n"
printf "\r\n"
cat /path/to/sample.html
) | nc -l 80 >/dev/null; do echo; done
Replace /path/to/sample.html
with the path of your actual HTTP file.
wget
and for serving you can program an own webserver, from your profile i see that you can java and c#. You just need to know a little bit of thehttp protocol
and ofberkeley sockets
and you can implement a simple web server serving a html file