nginx配置fcgi

1、刚开始用网上最多的方式,perl脚本实现cgi,配置最后都完成,一直是504错误,看日志是perl脚本连接超时,可能是版本太旧了吧,nginx更新用不了那种方式了,搞不清楚。貌似那种帖子都是13年的。

  比如这个:https://www.cnblogs.com/jiangu66/archive/2013/04/21/3033592.html


2、最后用别的方法:fcgiwrap【nginx官网链接】https://www.nginx.com/resources/wiki/start/topics/examples/fcgiwrap/
卧槽,官网还不知道怎么搜索,直接搜索不到,是百度fcgiwrap,然后直接点到这个页面来着
【ubuntu 安装】: 

1 aptitude install fcgiwrap
2 cp /usr/share/doc/fcgiwrap/examples/nginx.conf /etc/nginx/fcgiwrap.conf

  

按自己实际场景修改下/etc/nginx/fcgiwrap.conf

然后nginx配置包含(这一步不一定加,也可以直接把那几个配置拷贝到你的web server路径下面就行,像我下面那样):

include /etc/nginx/fcgiwrap.conf;

 

我的配置是这样的(本机测试服务器,所以浏览文件夹权限开放)http参数也全塞里面了,生产环境按需修改,注意权限控制安全性。

注:汉字注释一般去掉,免得会有异常,编码问题什么的。 

server {
        listen 81;
        listen [::]:81;

        # 这儿换成你自己的路径,注意文件夹权限
        set $web_root /home/webroot;
        root $web_root;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        #注意文件夹权限和文件权限(755)
        location ~ .*\.(cgi|rb|pl)$ {
                gzip off; #gzip makes scripts feel slower since they have to complete before getting gzipped  
                fastcgi_pass  unix:/var/run/fcgiwrap.socket;

                fastcgi_index index.rb;
                fastcgi_param SCRIPT_FILENAME           $web_root$fastcgi_script_name;
                fastcgi_param QUERY_STRING              $query_string;
                fastcgi_param REQUEST_METHOD            $request_method;
                fastcgi_param CONTENT_TYPE              $content_type;
                fastcgi_param CONTENT_LENGTH            $content_length;
                fastcgi_param GATEWAY_INTERFACE         CGI/1.1;
                fastcgi_param SERVER_SOFTWARE           nginx;
                fastcgi_param SCRIPT_NAME               $fastcgi_script_name;
                fastcgi_param REQUEST_URI               $request_uri;
                fastcgi_param DOCUMENT_URI              $document_uri;
                fastcgi_param DOCUMENT_ROOT             $web_root;
                fastcgi_param SERVER_PROTOCOL           $server_protocol;
                fastcgi_param REMOTE_ADDR               $remote_addr;
                fastcgi_param REMOTE_PORT               $remote_port;
                fastcgi_param SERVER_ADDR               $server_addr;
                fastcgi_param SERVER_PORT               $server_port;
                fastcgi_param SERVER_NAME               $server_name;

                fastcgi_connect_timeout         5;
                fastcgi_read_timeout            5;
                fastcgi_send_timeout            5;
        }

        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
}

 

posted @ 2018-01-11 11:53  fieldtianye  阅读(1654)  评论(0编辑  收藏  举报