• apache添加fastcgi支持


    A,安装apache服务器和fastcgi模块支持(ubuntu测试)

    sudo apt-get install apache2
    sudo apt-get install libapache2-mod-fastcgi

    apache2的配置文件目录如下:

    ciaos@ubuntu:/etc/apache2$ ll
    total 80
    drwxr-xr-x  7 root root  4096 May 28 21:33 ./
    drwxr-xr-x 93 root root  4096 May 28 21:44 ../
    -rw-r--r--  1 root root  8346 Feb  7  2012 apache2.conf
    drwxr-xr-x  2 root root  4096 May 28 21:32 conf.d/
    -rw-r--r--  1 root root  1322 Feb  7  2012 envvars
    -rw-r--r--  1 root root     0 May 28 21:32 httpd.conf
    -rw-r--r--  1 root root 31063 Feb  7  2012 magic
    drwxr-xr-x  2 root root  4096 May 28 21:36 mods-available/
    drwxr-xr-x  2 root root  4096 May 28 21:36 mods-enabled/
    -rw-r--r--  1 root root   750 Feb  7  2012 ports.conf
    drwxr-xr-x  2 root root  4096 May 28 21:58 sites-available/
    drwxr-xr-x  2 root root  4096 May 28 21:58 sites-enabled/

    配置fastcgi目录,只需要修改sites-enabled/000-default文件添加fastcgi的目录结构

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>
    
    ScriptAlias /fcgi-bin/ /var/lib/apache2/fastcgi/
    <Directory "/var/lib/apache2/fastcgi">
        AllowOverride None
        Options FollowSymLinks
        Order allow,deny
        Allow from all
        SetHandler fastcgi-script
    </Directory>

    重启apache服务器如下:

    sudo apachectl -k restart

    B,接下来写fastcgi程序测试(用C来测试)

    1,安装fastcgi库
    make的时候如果出现“error: 'EOF' was not declared in this scope”错误,则在出错文件加上#include <stdio.h>

    2,编辑个简单的fastcgi程序

    #include <fcgi_stdio.h>
    
    int main()
    {
            int count = 0;
            while(FCGI_Accept() >= 0) {
                    printf("Content-type: text/html
    ");
                    printf("
    ");
                    printf("Hello world!<br>
    ");
                    printf("Request number %d.", count++);
            }
            return 0;
    }

    3,编译并放到apache的cgi和fcgi目录下测试

    gcc sim.c -lfcgi -o test.cgi
    cp test.cgi /usr/lib/cgi-bin/
    访问 http://192.168.1.108/cgi-bin/test.cgi , 每次打印Request number都是0
    
    gcc sim.c -lfcgi -o test.fcgi
    cp test.fcgi /var/lib/apache2/fastcgi/
    访问 http://192.168.1.108/cgi-bin/test.fcgi , 每次打印Request number都会递增

    :如果ldd找不到依赖库,三种方法如下
    1,export LD_LIBRARY_PATH=/usr/local/lib/
    2,直接把so文件拷贝到/lib/目录下,这个目录一般都是
    3,/etc/ld.so.conf添加响应目录, /sbin/ldconfig –v更新

  • 相关阅读:
    bzoj2064分裂(dp)
    关于逆元的学习笔记(尚未完成)
    线性基学习笔记
    bzoj2460元素(线性基,贪心)
    CF280C Game on tree(期望dp)
    XJOI contest800
    关闭极域电子教室学生端的各种方法
    大坑!有网,电脑qq登不上去!!
    4.25 ZJOI2017 10AM
    bzoj1621
  • 原文地址:https://www.cnblogs.com/ciaos/p/3757999.html
Copyright © 2020-2023  润新知