Giuseppe Parrello

 

How to install a mini web server on a router


In this page I describe how to install a DLNA server on a router (Asus RT-AC56U) - we use an Entware installation, so please refer to this page on how to install Entware on a router.
We will use a mini web server called "minihttpd". Unfortunately this server cannot be found in Entware packages, it was included only at the time of the Optware packages.
The only way to have this server is to download the source code and compile the source code using the Entware compiling tools. I've already done this using router Asus RT-AC56U, achieving the final binary files.
Anyway I provide you with a .zip file containing all the files needed to execute this server, so download it, extract the files included in .zip file and then copy all extracted files to following folders:

FileDestination folder
index.html/opt/share/www/minihttp
mini_httpd/opt/sbin
mini_httpd.conf/opt/etc
mini_httpd-htpasswd/opt/sbin
S80minihttpd/opt/etc/init.d

All the above mentioned destination folders already exists in Entware installation, except "/opt/share/www/minihttp", we have to create it and then copy the file "index.html". Inside folder "/opt/share/www/minihttp" we have to create also a subfolder called "cgi-bin", as this mini web server supports also CGI-BIN scripts.
Firstly we need to setup the configuration file "mini_httpd.conf" placed in folder "/opt/etc". This is the provided configuration file:

# mini_httpd - small HTTP server config
# a hostname to bind to, for multihoming (set this at bind 0.0.0.0 problem)
#host=setthis

# a directory to chdir() to at startup
dir=/opt/share/www/minihttp

# a directory to chdir() to after chrooting
#data_dir=/opt/share/www

port=8084
user=nobody
nochroot
charset=iso-8859-2
cgipat=**.php|**.cgi|**.sh
logfile=/opt/var/log/mini_httpd.log
pidfile=/opt/var/run/mini_httpd.pid

# P3P server privacy header http://www.w3.org/P3P/
#p3p=
#vhost

This is a brief description of the most important variables included in above-mentioned configuration file:

Another step is to change the owner of all folder "/opt/share/www/minihttp" using the same "user" value inside configuration file, in this case "nobody", using the command line "chown -R nobody:nobody /opt/share/www/minihttp". Whenever we add a file inside the web server root folder "/opt/share/www/minihttp", we have also to change the owner of the added file.
After changing the owner of the above-mentioned folder, we can start the web server using the command line "/opt/etc/init.d/S80minihttpd start".
We can open the web browser and we can go to the address "http://[router address]:[port]" where "port" is the same "port" value used in configuration file. The browser should display the content of the file "index.html" included in the root folder of the web server.


How to setup an USERID and a password on web server

Normally when we start this mini web server, we can browse inside this web server without authentication. But we would like to a have an authentication procedure in order to grant this web server only to few users and not to all users.
This can be done using the command "mini_httpd-htpasswd" included in above-mentioned installation .zip file.
For example we want to use an user "admin" with password "admin", the command line to be executed is "mini_httpd-htpasswd -c testpwd admin", where the parameter after "-c" is the output file "testpwd", and the last parameter is the user name "admin", as for following example:

mini_httpd-htpasswd -c testpwd admin

Adding password for admin.
New password:
Re-type new password:


cat testpwd

admin:Yqm96b92BYBMw

The above-mentioned "testpwd" file contains a line "user:password" including an username and the encrypted password; obviously you can use more than one user inside the output file, you should remember to discard the "-c" parameter in command "mini_httpd-htpasswd" if the output file already exists.
Please note that the encrypted password is randomly created, so it will be never the same.
Finally we can add another user named "administrator" with password "admin":

mini_httpd-htpasswd testpwd administrator

Adding user administrator
New password:
Re-type new password:


cat testpwd

admin:Yqm96b92BYBMw
administrator:jloexXcjKyLcI

The above-mentioned "testpwd" file must be renamed to ".htpasswd" and must be copied to the root folder of the web server (default folder is "/opt/share/www/minihttp"). In this way whenever we open the browser and we go to the web server's internet address, the browser will ask for username-password authentication.