WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Lightweight Web Server on my RPI2  (Read 6333 times)

Offline mulletman87

  • Newbie
  • *
  • Posts: 27
Lightweight Web Server on my RPI2
« on: May 17, 2016, 11:26:08 PM »
Hi all,

I am looking for a very lightweight (used to use uHTTPd on openwrt) web server to serve a statistics page.

Any suggestions?

I was going to use Mongoose as there was a guide on using it on the forums already but it seems that the v7 repo doesn't have it (http://tinycorelinux.net/7.x/armv6/tcz/).

The web content (just html, js and css) is hosted in /opt/dest/www so I would just need to edit the config file of the package to point it to that location.

What would you use?

Thanks in advance :)


Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 402
Re: Lightweight Web Server on my RPI2
« Reply #1 on: May 18, 2016, 01:16:31 AM »
hi mulletman87,

We use busybox-httpd.tcz for piCorePlayer. It has meet our requirements to date.

So hundreds or maybe thousands of people are using it with no reported issues.

regards
Greg

Offline xyz-worx

  • Jr. Member
  • **
  • Posts: 69
Re: Lightweight Web Server on my RPI2
« Reply #2 on: May 18, 2016, 01:17:59 AM »
Hi mulletman87,

I would propose two web servers:

First, you could use busybox's internal simple web-server. As far as I know this is
an option on configuring/compiling busybox. Maybe one of the maintainers can give
you a hint, whether this option is present in busybox.

For my own purposes I use the monkey web-server: http://monkey-project.com/.
It's easy to configure and lightweight. It also can be extended with e. g. CGI if needed later.
The only drawback I see is, that there is no *.tcz upto now for direct download and install.
Therefore you  have to compile it from source which is not a big deal.

best regards

      xyz-worx

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Lightweight Web Server on my RPI2
« Reply #3 on: May 18, 2016, 01:59:48 AM »

First, you could use busybox's internal simple web-server. As far as I know this is
an option on configuring/compiling busybox. Maybe one of the maintainers can give
you a hint, whether this option is present in busybox.


piCore version was not mentioned. However busybox-httpd.tcz is in the piCore-6.x and piCore-7.x repo. It is worth to use tcz tools to check what is in the repo before rebuilding which is free for everyone of course :)

Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Lightweight Web Server on my RPI2
« Reply #4 on: May 18, 2016, 02:01:17 AM »
busybox-httpd work for me fine.
Handles HTML5, CGI, Javascript.
Have used CGI to run shell, micropython, Lua, Luajit scripts to do GPIO stuff.
I use dygraphs.js to plot from csv files, mostly just data plots.

Offline jgrulich

  • Sr. Member
  • ****
  • Posts: 341
    • GRULICH DESIGN - R&D Lab.
Re: Lightweight Web Server on my RPI2
« Reply #5 on: May 18, 2016, 05:36:30 AM »
busybox-httpd is simple and seems to be stable. It even support basic authentication for some folders, but doesn't support https.
Hence the security seems to be the same important question as the basic function, has anybody practical experience how robust it is against the hacker attacks?

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Lightweight Web Server on my RPI2
« Reply #6 on: May 18, 2016, 05:40:25 AM »
busybox-httpd is simple and seems to be stable. It even support basic authentication for some folders, but doesn't support https.
Hence the security seems to be the same important question as the basic function, has anybody practical experience how robust it is against the hacker attacks?

What kind of hacker attack? It is too generic. Usually not the web server itself hacked but via PHP code, SQL injection, etc. Working with simple static pages or CGI can be safe.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline jgrulich

  • Sr. Member
  • ****
  • Posts: 341
    • GRULICH DESIGN - R&D Lab.
Re: Lightweight Web Server on my RPI2
« Reply #7 on: May 18, 2016, 06:08:14 AM »
Guess the web pages modification / infection. Any possible way?
Which ports are open for infection? For sure :80, but no other?

Online patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 661

Offline mulletman87

  • Newbie
  • *
  • Posts: 27
Re: Lightweight Web Server on my RPI2
« Reply #9 on: May 18, 2016, 07:06:18 AM »
Thanks everyone, I think I will go with busybox-httpd.tcz, looks good.

I will just set the www directory to /opt/dest/www within the config file which I presume should be easy enough.

Really appreciate the feedback.

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Lightweight Web Server on my RPI2
« Reply #10 on: May 18, 2016, 08:29:45 PM »
I have two spots where I stick the HTML files.
/home/tc/www
or I make and use the third partition /mnt/mmcblk0p3/data/www
May need to make a symbolic link to /mnt/mmcblk0p3/.....

I save data to the third partition, trying to leave mmcblk0p1 and 2 untouched.
Mainly to make for long lifetime of the SD card.
Two units running for 18+ months saving data every 5 minutes, still working 24/7 :P

Offline mulletman87

  • Newbie
  • *
  • Posts: 27
Re: Lightweight Web Server on my RPI2
« Reply #11 on: May 19, 2016, 07:28:14 AM »
Thanks @gavinmc42 - I definitely need to preserve the life the the SD card so that info is valuable for me, thanks!

I did install it today and fired it up by typing:

sudo /usr/local/sbin/busybox-httpd -p 80 -h /opt/dest/www/ -u tc:staff

I checked if the process was running using:

ps -e | grep busy

I am now getting a 404 error which I am 99% sure is now due to my web content giving issues so I will sort that out tomorrow (in this case, I am happy about the 404 because it means it is at least finding a webserver hehe).

Thanks for the help everyone.

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Lightweight Web Server on my RPI2
« Reply #12 on: May 19, 2016, 05:45:39 PM »
Missing index.html?
That is the default for busybox-httpd

call below code a file ledon.cgi, stick it in www/cgi-bin/
button on the HTML5 page calls the ledon.cgi file, now you have web control of GPIO.

#!/bin/sh
#echo "Content-type: text/html"
#echo ""
#echo "LED 22 is on"
echo 1 > /sys/class/gpio/gpio22/value
echo "HTTP/1.1 303 Found"
echo "Location: /index.html"

.cgi files are just scripts, could be a shell file calling micropython, lua, luajit etc
Anything that can run by calling it.

The trick to CGI is the echo "HTTP1.1 xxx" codes, 204, 303 etc


Offline mulletman87

  • Newbie
  • *
  • Posts: 27
Re: Lightweight Web Server on my RPI2
« Reply #13 on: May 29, 2016, 07:44:21 AM »
@gavinmc42, thank you, all sorted, really appreciate it.

Offline gavinmc42

  • Sr. Member
  • ****
  • Posts: 301
Re: Lightweight Web Server on my RPI2
« Reply #14 on: May 31, 2016, 01:48:51 AM »
I am putting this here in case I forget how to do it, which I just did;)

busybox-httpd likes to have cgi-bin and data files under it's directory.

So if your data gets stored on mmcblk0p3 you need to make a symbolic link to it

cd /home/tc/www
ln -s /mnt/mmcblk0p3/data/logs ./logs


Don't forget to mount mmcblk0p3 on boot, put this in the /opt/bootsync.sh file

mount -w /dev/mmcblk0p3

your cgi-bin code can now find the log files for plotting.
This is my file called select.cgi, just some shell script that goes in /home/tc/www/cgi-bin/
My html file uses Chrome's  input type="date" which does not work in Firefox as I found today.

   <form action="cgi-bin/select.cgi">
   Select file:
   <input type="date" name="date">
   
   <input type="submit">
   </form>


select.cgi

#!/bin/sh

echo $QUERY_STRING | awk -F'[=&]' '{print $2}' > /home/tc/day1

sed 's/-/_/g' /home/tc/day1 > /home/tc/day2
day=$( cat /home/tc/day2 )

selected="Data_"$day".csv"
echo $selected > /mnt/mmcblk0p3/www/file.ini


echo "HTTP/1.1 303 found"
echo "Location: /plot.html?"$selected
echo ""