Nginx上的cgi-bin获取502错误的网关(perl)

时间:2018-12-12 04:01:43

标签: perl nginx cgi fastcgi

我尝试使用fcgiwrap在Nginx中提供CGI脚本,这是我的步骤:

  1. 易于安装fcgiwrap
  2. sudo vi /etc/nginx/sites-enabled/www.example.com.conf并将脚本部分添加到服务器{}中,如下所示:

    location /cgi-bin/ {
         # Disable gzip (it makes scripts feel slower since they have to complete
         # before getting gzipped)
         gzip off;
         # Set the root to /usr/lib (inside this location this means that we are
         # giving access to the files under /usr/lib/cgi-bin)
         root  /var/www/www.example.com;
         # Fastcgi socket
         fastcgi_pass  unix:/var/run/fcgiwrap.socket;
         # Fastcgi parameters, include the standard ones
         include /etc/nginx/fastcgi_params;
         # Adjust non standard parameters (SCRIPT_FILENAME)
         fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }
    
  3. 然后重新加载Nginx

  4. mkdir /var/www/www.example.com/cgi-bin
  5. sudo vi /var/www/www.example.com/cgi-bin/hello_world.cgi
  6. sudo chmod 755 /var/www/www.example.com/cgi-bin/hello_world.cgi
  7. 打开http://www.example.com/cgi-bin/hello_world.cgi

但是当我打开http://www.example.com/cgi-bin/hello_world.cgi时,我得到了502错误的网关,并且显示了此错误日志:

2018/12/12 10:18:38 [error] 10438#10438: *645 upstream prematurely closed FastCGI stdout while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: http://www.example.com, request: "GET /cgi-bin/hello.cgi HTTP/2.0", upstream: "fastcgi://unix:/var/run/fcgiwrap.socket:", host: "http://www.example.com"

笔记:但是当我将/var/run/fcgiwrap.socket更改为/etc/init.d/fcgiwrap时,我得到了不同的错误日志:

2018/12/12 11:06:52 [error] 15393#15393: *1 connect() to unix:/etc/init.d/fcgiwrap failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: http://www.example.com, request: "GET /cgi-bin/hello.cgi HTTP/2.0", upstream: "fastcgi://unix:/etc/init.d/fcgiwrap:", host: "http://www.example.com"

所以,我该如何解决这个错误?

0 个答案:

没有答案