使用bash写fastcgi程序时,一定要先输出Content-type和一个空行,不然nginx会报错502 Bad Gateway,后台访问日志中会有”upstream prematurely closed FastCGI stdout while reading response header from upstream”错误。
下面两种写法皆可:
#!/bin/bash echo -e "Content-type: text/html\n"
或者
#!/bin/bash echo "Content-type: text/html"echo ""
之后可以继续输出text或者html文本
原文地址:bash fastcgi输出内容类型, 感谢原作者分享。 业精于勤,荒于嬉;行成于思,毁于随。