如何从cgi-bin提供HTML?

时间:2014-05-16 17:55:14

标签: html bash cgi sh openwrt

我在OpenWrt 12.09上运行uhttpd。我在/ www / cgi-bin / test上有一个shell脚本,如下所示:

#!/bin/sh
echo "Content-type: text/html"
echo "<p>It works!</p>"

我通过在chmod +x上执行文件执行权限。所有者是root,uhttpd以root身份运行。

现在当我去http://192.168.1.1/cgi-bin/test时出现错误:

The CGI process did not produce any response

系统或内核日志中没有错误。

我可以转到http://192.168.1.1/cgi-bin/luci并获取LuCI登录页面,因此其他CGI脚本正在运行。该文件具有不同的shebang(#!/usr/bin/lua),但两个脚本具有相同的权限和所有者。

我做错了什么?

1 个答案:

答案 0 :(得分:5)

必须是HTTP标头和正文之间的空行。此外,您可能希望提供完整的HTML文档。

#!/bin/sh
echo "Content-type: text/html"
echo 
echo "<html><head><title>hello world</title></head><body><p>It works!</p></body>"