Ubuntu16.04配置Nginx支持FastCGI

关于在 Ubuntu 16.04上安装 Nginx, MySQL, PHP (LEMP),上一篇文章已经讲过

http://blog.csdn.net/shihongliang1993/article/details/51836262


安装spawn-fcgi


  • sudo apt-get install spawn-fcgi
安装完成之后, spawn-fcgi的目录为 /usr/bin/spawn-fcgi

编写简单C程序

创建文件testcgi。c,输入以下内容进行测试。

  • #include  
    #include  
    #include  
    int main() 
    {
    int count = 0;
    while(FCGI_Accept() >= 0){
    printf("Content-type: text/html\r\n"
    "\r\n"
    ""
    "FastCGI Hello!"
    "Request number %d running on host%s "
    "Process ID: %d\n", ++count, getenv("SERVER_NAME"));
    }
    return 0;
    }
编译程序

  • g++ testcgi.c -o upload  -lfcgi

将编译成功的upload复制到工作目录(随意)

  • mkdir /usr/share/nginx/cgi-bin
    cp upload /usr/share/nginx/cgi-bin

启动spawn-fcgi


  • /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9002 -C 25 -f /usr/share/nginx/cgi-bin/upload
成功启动提示如下



更改Nginx配置


  • sudo vim /etc/nginx/sites-available/default
添加以下内容

  • location ~ \.cgi$ {
            fastcgi_pass 127.0.0.1:9002;
  •         fastcgi_index index.cgi;
            fastcgi_param SCRIPT_FILENAME fcgi$fastcgi_script_name;
            include fastcgi_params;
        }
重启Nginx


  • sudo service nginx restart

测试

在浏览器输入以下网址

  • http://10.102.7.193/upload.cgi
显示以下内容,则为成功

你可能感兴趣的:(Linux系统问题解决方案)