前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >http+cgi实现(使用lighttp)

http+cgi实现(使用lighttp)

作者头像
用户3765803
发布2019-03-05 09:48:34
1.1K0
发布2019-03-05 09:48:34
举报
文章被收录于专栏:悟空被FFmpeg玩悟空被FFmpeg玩

做法比较简单 首先将lighttpd配置好 然后修改一下配置文件

点击(此处)折叠或打开

  1. server.modules = (
  2. "mod_access",
  3. "mod_cgi",
  4. "mod_accesslog" )
  5. server.document-root = "/www/pages/"
  6. server.errorlog = "/www/logs/lighttpd.error.log"
  7. index-file.names = ( "index.php", "index.html",
  8. "index.htm", "default.htm" )
  9. mimetype.assign = (
  10. ".pdf" => "application/pdf",
  11. ".sig" => "application/pgp-signature",
  12. ".spl" => "application/futuresplash",
  13. ".class" => "application/octet-stream",
  14. ".ps" => "application/postscript",
  15. ".torrent" => "application/x-bittorrent",
  16. ".dvi" => "application/x-dvi",
  17. ".gz" => "application/x-gzip",
  18. ".pac" => "application/x-ns-proxy-autoconfig",
  19. ".swf" => "application/x-shockwave-flash",
  20. ".tar.gz" => "application/x-tgz",
  21. ".tgz" => "application/x-tgz",
  22. ".tar" => "application/x-tar",
  23. ".zip" => "application/zip",
  24. ".mp3" => "audio/mpeg",
  25. ".m3u" => "audio/x-mpegurl",
  26. ".wma" => "audio/x-ms-wma",
  27. ".wax" => "audio/x-ms-wax",
  28. ".ogg" => "application/ogg",
  29. ".wav" => "audio/x-wav",
  30. ".gif" => "image/gif",
  31. ".jpg" => "image/jpeg",
  32. ".jpeg" => "image/jpeg",
  33. ".png" => "image/png",
  34. ".xbm" => "image/x-xbitmap",
  35. ".xpm" => "image/x-xpixmap",
  36. ".xwd" => "image/x-xwindowdump",
  37. ".css" => "text/css",
  38. ".html" => "text/html",
  39. ".htm" => "text/html",
  40. ".js" => "text/javascript",
  41. ".asc" => "text/plain",
  42. ".c" => "text/plain",
  43. ".cpp" => "text/plain",
  44. ".log" => "text/plain",
  45. ".conf" => "text/plain",
  46. ".text" => "text/plain",
  47. ".txt" => "text/plain",
  48. ".dtd" => "text/xml",
  49. ".xml" => "text/xml",
  50. ".mpeg" => "video/mpeg",
  51. ".mpg" => "video/mpeg",
  52. ".mov" => "video/quicktime",
  53. ".qt" => "video/quicktime",
  54. ".avi" => "video/x-msvideo",
  55. ".asf" => "video/x-ms-asf",
  56. ".asx" => "video/x-ms-asf",
  57. ".wmv" => "video/x-ms-wmv",
  58. ".bz2" => "application/x-bzip",
  59. ".tbz" => "application/x-bzip-compressed-tar",
  60. ".tar.bz2" => "application/x-bzip-compressed-tar"
  61. )
  62. accesslog.filename = "/www/logs/access.log"
  63. url.access-deny = ( "~", ".inc" )
  64. cgi.assign = (
  65. ".cgi" =>"")

然后在目录下编译一个cgi执行文件就可以了

点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(void)
  4. {
  5.     char *data;
  6.     long m,n;
  7. int len = 0;
  8.         char execname[512];
  9.         char argvs[512];
  10.         char *request_method;
  11.         char *client_ip;
  12.         char *content_type;
  13.         memset(execname, 0, 512);
  14.         memset(argvs, 0, 512);
  15.     printf("%s\n\n","Content-Type:text/html;charset=gb2312");
  16.     printf("multi ");
  17.     printf("multi total ");
  18.         content_type = getenv("CONTENT_TYPE");
  19.         fprintf(stdout, "%s\n", content_type);
  20.         client_ip = getenv("REMOTE_ADDR");
  21.         fprintf(stdout, "|%s|\n", client_ip);
  22.         request_method = getenv("REQUEST_METHOD");
  23.         fprintf(stdout, "|%s|\n", request_method);
  24. if ( !strncasecmp(request_method, "POST", 4) ) {
  25.                 data = getenv("CONTENT_LENGTH");
  26. len = atoi(data);
  27. } else {
  28.         data = getenv("QUERY_STRING");
  29.                 strncpy(execname, data, strlen(data));
  30. }
  31.         fgets(execname, len + 1, stdin);
  32.         fprintf(stdout, "|%s|\n", execname);
  33. if(data == NULL)
  34.         printf("error no data");
  35.     return 0;
  36. }

编译以后执行,使用GET或者POST都可以

点击(此处)折叠或打开

  1. <html>
  2. <body>
  3. <form name="form1" ACTION="/test.cgi" method=post >
  4. <P>this is a page<BR>
  5.             srcname: <INPUT NAME="srcname" SIZE="5"><BR><BR>
  6.             destname: <INPUT NAME="destname" SIZE="5"><BR><BR>
  7.             dest codec: <INPUT NAME="mpeg4" SIZE="5"><BR><BR>
  8. <INPUT TYPE="SUBMIT" values="test">
  9. </form>
  10. </body>
  11. </html>

这样就可以了,输入以后,会在页面里打印出来

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2012-03-22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档