zoukankan      html  css  js  c++  java
  • CentOS7配置Nginx+Spawn-fcgi+fcgi(新)

    注:全局使用超级用户root进行配置

    1.准备

    nginx-1.12.2.tar.gz(来源:wget http://nginx.org/download/nginx-1.12.2.tar.gz)

    spawn-fcgi-1.6.4.tar.gz(来源:wget http://download.lighttpd.net/spawn-fcgi/releases-1.6.x/spawn-fcgi-1.6.4.tar.gz)

    fcgi-2.4.0.tar.gz(来源:wget http://down1.chinaunix.net/distfiles/fcgi-2.4.0.tar.gz)

    tar -xzvf 压缩包  #进行解压

    2.安装Nginx

    (1)执行:yum -y install pcre-devel  #HTTP rewrite module requires the PCRE library

    (2)执行:yum -y install zlib-devel  #HTTP gzip module requires the zlib library

    (3)执行:yum -y install openssl-devel  #SSL modules require the OpenSSL library

    (4)执行:./configure --with-http_ssl_module

    运行结果:

    Configuration summary
    + using system PCRE library
    + using system OpenSSL library
    + using system zlib library

    nginx path prefix: "/usr/local/nginx"
    nginx binary file: "/usr/local/nginx/sbin/nginx"
    nginx modules path: "/usr/local/nginx/modules"
    nginx configuration prefix: "/usr/local/nginx/conf"
    nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
    nginx pid file: "/usr/local/nginx/logs/nginx.pid"
    nginx error log file: "/usr/local/nginx/logs/error.log"
    nginx http access log file: "/usr/local/nginx/logs/access.log"
    nginx http client request body temporary files: "client_body_temp"
    nginx http proxy temporary files: "proxy_temp"
    nginx http fastcgi temporary files: "fastcgi_temp"
    nginx http uwsgi temporary files: "uwsgi_temp"
    nginx http scgi temporary files: "scgi_temp"

    (5)执行:make && make install  #编译及安装

    (6)查看安装位置:whereis nginx

    结果:

    nginx: /usr/local/nginx

    3.spawn-fcgi安装

    (1)执行:./configure

    (2)执行:make && make install

    (3)查看版本:spawn-fcgi -v

     结果:

    spawn-fcgi v1.6.4 - spawns FastCGI processes

    4.fcgi库安装

    (1)执行:./configure

    (2)修改include/fcgio.h文件,加入#include <stdio.h>  #防止出现编译错误:error: 'EOF' was not declared in this scope

    (3)执行:make && make install

    5.fcgi编程

    (1)样例代码

    #include <fcgi_stdio.h>
    
    int main(int argc, char *argv[])
    {
            while( FCGI_Accept() >=0 )
            {
                    FCGI_printf("Content-Type: text/html
    
    ");
                    FCGI_printf("Hello world!");
            }
    
            return 0;
    }
    

    (2)编译:g++ -o test.fcgi test.cpp -L/usr/local/lib -lfcgi

    (3)测试运行:./test.fcgi

    如果出现类似错误:

    ./test.fcgi: error while loading shared libraries: libfcgi.so.0: cannot open shared object file: No such file or directory

     则进行如下处理:

    将路径/usr/local/lib添加到文件/etc/ld.so.conf的末尾

    文件打开命令可以使用:visudo  #vi /etc/ld.so.conf  //或者用vi命令

    变更后,形如:

    include ld.so.conf.d/*.conf
    /usr/local/lib
    

     运行ldconfig命令马上生效

    (参考:https://www.cnblogs.com/chris-cp/p/3591306.html

     5.启动fcgi应用程序

    (1)将fcgi程序统一存储至一个目录,例如:cp test.fcgi /usr/local/nginx/fcgi-bin

    (2)启动程序:spawn-fcgi -a 127.0.0.1 -p 9001 -F 10 -f /usr/local/nginx/fcgi-bin/test.fcgi

     6.启动nginx

    (1)打开配置文件:vi conf/nginx.conf

    (2)将原配置:

            #location ~ .php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}
    

      改为:

            location = /test.fcgi {
            #    root           html;
                fastcgi_pass   127.0.0.1:9001;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
                include        fastcgi_params;
            }
    

    (3)启动:./nginx  #./nginx -s reload //重新加载

    7.Http访问

     8.服务器外部访问

    打开服务器外部访问端口,重启防火墙:

    firewall-cmd --add-port=80/tcp --permanent
    firewall-cmd --reload
    

      

  • 相关阅读:
    Android中Handler原理
    微软柯塔娜(Cortana)的一句名言
    C# 单例模式的五种写法
    HTTP Status 404
    PLSQL中显示Cursor、隐示Cursor、动态Ref Cursor差别
    Android 开发之集成百度地图的定位与地图展示
    iOS知识点汇总
    优化报表系统结构之报表server计算
    淘宝中间的一像素线(手机端)
    解决yum升级的问题“There was a problem importing one of the Python modules”
  • 原文地址:https://www.cnblogs.com/baipengchao/p/8309889.html
Copyright © 2011-2022 走看看