As LuaRocks is unfortunately not part of the FreeBSD ports collection, it has to be compiled manually. As I’m going to need to repeat this process in the foreseeable future, I decided to document the required steps here.
The reason why I’m targeting Lua 5.1 specifically is that I’m installing Luarocks to build rocks to be used with the Nginx Lua module, as I plan to migrate the Telize server to FreeBSD.
Installing Lua and some required packages
pkg install lua51 gmake curl
Fetching, unpacking, and configuring using Curl as downloader
curl -O http://luarocks.org/releases/luarocks-2.2.0.tar.gz
tar xvfz luarocks-2.2.0.tar.gz
cd luarocks-2.2.0./configure --with-lua-include=/usr/local/include/lua51 --with-downloader=curl
make build && make install
Building and installing some Lua modules
luarocks build lua-cjson
luarocks build lua-iconv
Verifying that our modules have been built and installed successfully
I’ve been working a lot on JSON APIs during the past few years, and even more intensively lately. If testing GET requests is straightforward, for POST requests I often had to look at Curl documentation again for exact options names and parameter syntax for sending the desired HTTP headers.
So I decided to post some quick notes on doing unauthenticated POST requests, in order to have a quickly accessible reference.
Here is a list of some relevant Curl options :
-d, --dataDATA HTTP POST data (H)
-X, --request COMMAND Specify request command to use
-H, --header LINE Custom headerto pass to server (H)
Doing an empty POST request
curl --request POST http://127.0.0.1:8080/api/store
Specifying the package option when invoking make will create a binary package in /usr/pkgsrc/packages/All. As compiling can take a long time on the Pi, this is especially handy when doing reinstalls or using multiple boards.
Here is the list of packages which have been created :
So far, running NetBSD on the Raspberry Pi has been a very positive experience and the system is very stable. I would definitely recommend anyone wanting to use BSD on the Pi to give NetBSD a try, it’s well worth it.
I should probably also mention that it’s smaller than a toaster :-)
Server Side Includes are an interesting way to embed content dynamically into static files. It can be particularly useful to inject information about the visitor or to add headers, footers or any file containing data changing over time.
Please note, however, that Nginx does not implement the full SSI specification yet. More information about what is currently supported can be found in the ngx_http_ssi_module documentation.
To enable SSI, the following directive must be added in the http, server or location block :
Here is an example HTML snippet with SSI directives, showing how to echo variables and include content from other files :
In order to populate fortune.txt and uptime.txt, we can use Cron and refresh files content as required. For even more fun, we can also use cowsay together with fortune.
Finally, here is the resulting output when accessing the page using Lynx :
Visitor IP address : 18.104.22.168
Visitor User agent : Lynx/2.8.8rel.2 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/1.0.1h
Server local time : Sunday, 21-Sep-2014 18:55:49 CEST
Server time (GMT) : Sunday, 21-Sep-2014 16:55:49 GMT
Server uptime : 18:55:01 up 52 days, 7:50, 3 users, load average: 0.13, 0.19, 0.22
Fortune of the day
/ In most countries selling harmful \
| things like drugs is punishable. Then |
| howcome people can sell Microsoft |
| software and go unpunished? |
\ -- Hasse Skrifvars, email@example.com, /
// \ \
(| | )