大网数据广告活动
服务器运维问答

Nginx and fcgiwrap, incremental output problems

· 52CE 我爱测

When I run a cgi script under Apache any output is rapidly sent to the client. However when I run it under nginx with fcgiwrap it seems nothing is sent to the client until the script either finishes or produces a lot of output. I…

问题原文

原帖链接 · Peter Green · CC BY-SA 4.0

When I run a cgi script under Apache any output is rapidly sent to the client. However when I run it under nginx with fcgiwrap it seems nothing is sent to the client until the script either finishes or produces a lot of output. In particular when using git-http-backend this leads to gateway timeouts on cloning large repositories (and lack of progress information on cloning smaller ones).

This behaviour can be seen with the following script.

 #!/bin/bash
 echo "Content-type: text/html"
 echo
 while :
 do
       echo this is a test.
       sleep 5
 done

Under apache the client will get some data every 5 seconds.

Under nginx with fcgiwrap I get no data and a gateway timeout.

nginx and fcgiwrap are packages from Debian Jessie. Versions 1.1.0-5 and 1.6.2-5+deb8u4

So the questions

  1. Does anyone know which is responsible for this behaviour? nginx itself? fcgiwrap? both?
  2. Is it something that can be fixed through configuration?
  3. If it's a fcgiwrap problem are there alternative cgi wrappers available that don't suffer the problem?

已采纳解答

原帖链接 · Peter Green · CC BY-SA 4.0

Ok, figured it out. It seems both nginx and fcgiwrap have undesirable buffering in place. For nginx it seems it can be disabled through configuration while fcgiwrap needs a patch.

I have posted a debdiff for fcgiwrap at http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=863478 this adds a new option NO_BUFFERING

(update: Debian has now applied said patch, so if you are running Debian Buster or later you don't need to apply it yourself).

Then the nginx configuration needs changing to pass the NO_BUFFERING option to fcgiwrap and to disable buffering inside nginx.

To do this I added some settings immediately before and after the "include fastcgi_params;" line.

    #note: NO_BUFFERING relies on a patched fcgiwrap.
    fastcgi_param NO_BUFFERING 1;
    include fastcgi_params;
    gzip off;
    fastcgi_buffering off;

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-05-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。