lighttpd 服务器搭建过程记录2【with CGI】

来源:互联网 发布:淘宝生产许可证 编辑:程序博客网 时间:2024/05/16 07:12

1、 补上 pcre 的安装

   因为要配置cgi,需要这个库。

    如果可以使用yum,则非常简单,使用 yum install pcre-deve  即可!!!!

    如果不可以也没关系,下载官网的,随便一个版本吧。 下载解压,执行 confiure 和 make 和 make install 即可

  。详细的过程参考:http://chenzhou123520.iteye.com/blog/1817563


 2、 按照好 pcre 后, 还是得把  lighttpd  重新安装一遍,在 执行 confiure 的时候不要加 without-pcre 了。


3、修改配置

    把 lighttpd.conf  modules.conf   cgi.conf 里面支持 cgi 的都配置下。

比较关键的是:

1)lighttpd.conf   里面

       原来是: static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".scgi )

      现在是:static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".scgi",".cgi" )

2)cgi.conf  里面

原来是: ##$HTTP["url"] =~ "^/cgi-bin" {
   cgi.assign = ( "" => "" )

现在是:

$HTTP["url"] =~ "^/cgi-bin" {
   cgi.assign = ( "" => "" )


4、编写cgi 程序

在 htdocs 下建立 目录 cgi-bin , 后面的程序都放在 这个里面,且后缀改为 .cgi。

1)C 语言的例子

一个C语言的demo:[是 \n ,不是/n]  非常重要!!!!

#include   <stdio.h>    
int   main()    
{    
      printf("content-type:text/html\n\n");    
      printf("<html>");    
      printf("<head><title>file</title></head><body>");    
      printf("Hello,world by CGI!<br/>");    
      printf("</body></html>");    
}  

2)shell 的例子

一个shell 的dmeo:
#! /bin/bash
echo Content-type: text/html
echo ""
echo Hello, World by bash!


5、执行 127.0.0.1:8080/cgi-bin/hello.cgi

即可!

0 0