uhttpd + Fast-CGI的开发要求:
安装uhttpd包(https需要加装“uhttpd-mod-tls”和“px5g”);
修改uhttpd配置文件“/etc/config/uhttpd”,将Lua作为“interpreter”;
Lua脚本写到“/www/cgi-bin/”目录下,但是不带扩展名,且可执行;
Fast-CGI要求Lua脚本必须首先使用“io.write()”输出“Content-type: text/html\n\n”;
“/www/cgi-bin/”目录下的脚本可以调用“/usr/lib/lua/”目录下的自定义模块;
Lua环境已经就绪。
以“读取GET和POST数据”为例,全部使用默认值的情况下,如何具体实现:
第一步:使用“opkg update”更新“.ipk”包的源,然后使用“opkg install uhttpd”安装;
第二步:使用“vi /etc/config/uhttpd”,在“config uhttpd main”下添加一行
list interpreter ".lua=/usr/bin/lua”
第三步:建立目录“/www/cgi-bin”,并增加“+x”属性;
root@OpenWrt:~# mkdir -p /www/cgi-bin/
root@OpenWrt:~# chmod +x /www/cgi-bin/
建立响应文件,并增加“+x”属性;
root@OpenWrt:~# touch /www/