Pages

Showing posts with label web server. Show all posts
Showing posts with label web server. Show all posts

Saturday, April 6, 2013

The SMILE as a Content Web Server

I wanted to configure the SMILE to serve static content from the micro-SD card. It was fairly simple.

First, I installed nginx on the SMILE. I then mounted the SD card.

Finally, I had to configure nginx to serve content from the card (mounted as /media/sdcard), which is what this post is about.

The main configuration file is /etc/nginx/nginx.conf. First, we'll change the port on which nginx listens. The default port is 80, but this is already being used by the SMILE software. We can disable the SMILE software, and we'll talk about it in an upcomign post. But in the meantime, let's just change the nginx port. So we'll change the following line:
listen       80;
into
listen       8080;
The next change will be the location of the documents. The default root directory for the content is /usr/share/nginx/html. We have two options here. Either edit the nginx.conf file to change the directory, or add a soft link from /usr/share/nginx/html to /media/sdcard. For the first method, you'll need to change the nginx.conf line
root   /usr/share/nginx/html;
into
root   /media/sdcard;
The second method involves first deleting (or renaming) the /usr/share/nginx/html directory, then adding a soft link instead. Here's how to about this path:
cd /usr/share/nginx/
mv html html.orig
ln -s /media/sdcard/ html
That's it! You can now go to http://10.1.0.1:8080 (assuming you're connected wirelessly to the SMILE), and assuming you have an index.html (or index.htm) in your SD card's top directory, you should see it now in your browser. If yo're getting a 403 error, it means you probably don't have an index.html file on the SD card.

Running nginx is simple - you basically type nginx at the shell prompt:
root@SMILEplug:~# nginx
In case nginx is already running, you can issue the following command  to reload the configuration file:

root@SMILEplug:~# nginx -s reload

Installing nginx

nginx is a light, super-fast web server. To install it on SMILE plug, sign in as root, and simply install the nginx package using pacman. I noticed that a package database sync was required first, so run a sync (pacman -Sy) first. Make sure your plug is connected to the web.


root@SMILEplug:/etc# pacman -Sy
:: Synchronizing package databases...
 core                                                                  45.4 KiB  11.9K/s 00:04 [#######################################################] 100%
 extra                                                                507.3 KiB  27.4K/s 00:18 [#######################################################] 100%
 community                                                            510.7 KiB  26.6K/s 00:19 [#######################################################] 100%
 alarm                                                                  8.3 KiB   227K/s 00:00 [#######################################################] 100%
 aur                                                                   19.9 KiB  4.99K/s 00:04 [#######################################################] 100%
root@SMILEplug:/etc# pacman -S nginx
resolving dependencies...
looking for inter-conflicts...

Targets (3): geoip-1.4.8-2  geoip-database-20130206-1  nginx-1.2.7-5

Total Download Size:    0.97 MiB
Total Installed Size:   3.72 MiB


Proceed with installation? [Y/n] y
:: Retrieving packages from extra...
 geoip-database-20130206-1-any                                        679.3 KiB  26.1K/s 00:26 [#######################################################] 100%
:: Retrieving packages from community...
 nginx-1.2.7-5-armv7h                                                 311.0 KiB  21.6K/s 00:14 [#######################################################] 100%
(3/3) checking package integrity                                                               [#######################################################] 100%
(3/3) loading package files                                                                    [#######################################################] 100%
(3/3) checking for file conflicts                                                              [#######################################################] 100%
(3/3) checking available disk space                                                            [#######################################################] 100%
(1/3) installing geoip-database                                                                [#######################################################] 100%
(2/3) installing geoip                                                                         [#######################################################] 100%
(3/3) installing nginx                                                                         [#######################################################] 100%
root@SMILEplug:/etc#