通过 nginx 提供 fastcgi

thp*_*rus 4 nginx fcgi

我有一个在 127.0.0.1:9000 上运行的“hello world”fastcgi,并希望通过 nginx 为其提供服务。我将以下几行添加到 nginx.conf http 块中:

server {
    listen public.ip.address.here:80;
    server_name $host;

    location / {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我没有得到 fastcgi 的输出,而是只得到 502 Bad Gateway 响应。

error_log 说:[error] 1924#0: *1 upstream prematurely closed FastCGI stdout while reading response header from upstream, client: myIP, server: $host, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "public.ip.address.here"

小智 5

当我忘记通过在 CGI 内容之前添加这三行输出来将 CGI 转换为 FastCGI 时,我遇到了同样的问题:

print "HTTP/1.0 200 OK"
print "Content-type: text/plain"
print ""
Run Code Online (Sandbox Code Playgroud)