FastCGI Cannot execute script while reading response header from upstream

71 views Asked by At

Basically I have FastCGI configured in NGINX to use it for taking screenshots of my streamings but it doesnt seem to work. Every time I send a request like this:

http://localhost:8080/thumbnail?test

I receive this error in my docker logs

172.18.0.1 - - [21/Jan/2024:00:25:44 +0000] "GET /thumbnail?test HTTP/1.1" 301 169 "-" "PostmanRuntime/7.36.1"
2024/01/21 00:25:44 [error] 21#21: *4 FastCGI sent in stderr: "Cannot execute script (/usr/share/nginx/cgi-bin/thumbnail.cgi)" while reading response header from upstream, client: 172.18.0.1, server: , request: "GET /thumbnail/?test HTTP/1.1", upstream: "fastcgi://unix:/var/run/fcgiwrap.socket:", host: "localhost:8080", referrer: "http://localhost:8080/thumbnail?test"
172.18.0.1 - - [21/Jan/2024:00:25:44 +0000] "GET /thumbnail/?test HTTP/1.1" 502 28 "http://localhost:8080/thumbnail?test" "PostmanRuntime/7.36.1"

This is my nging.conf file

events {}
rtmp {
    server {
        listen 1935; # puerto por defecto para rtmp

        application live {
            live on;
            hls on;
            hls_path /tmp/hls;
            hls_fragment 5s; # default 5s
            hls_playlist_length 30s; # default 30s
            # para permitir CORS
            # add_header Access-Control-Allow-Origin *;

            # authentication
            on_publish http://auth_server:8000/auth;
        }
    }
}

http {
    server {
        listen 8080;

        location / {
            root /www;
        }

        location /hls {
            types {
                application/vnd.apple.mpegurl m3u8;
                application/octet-stream ts;
            }
            root /tmp;
            add_header Cache-Control no-cache;

            # para permitir CORS
            add_header Access-Control-Allow-Origin *;
        }

        location /stat {
            rtmp_stat all;

            # para permitir CORS
            add_header Access-Control-Allow-Origin *;
        }

        location /thumbnail/ {
            gzip off;
            root /usr/share/nginx;
            fastcgi_pass unix:/var/run/fcgiwrap.socket;
            include /etc/nginx/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root/cgi-bin/thumbnail.cgi;
            fastcgi_param DOCUMENT_ROOT $document_root;
            fastcgi_index thumbnail.cgi;
            fastcgi_read_timeout 300;
            fastcgi_buffers 8 16k;
            fastcgi_buffer_size 32k;
        }

    }
}

This is my Dockerfile

FROM tiangolo/nginx-rtmp

RUN apt-get update && \
    apt-get install -y fcgiwrap && \
    update-rc.d fcgiwrap defaults 20

COPY nginx.conf /etc/nginx/nginx.conf
COPY index.html /www/
COPY thumbnail.cgi /usr/share/nginx/cgi-bin/thumbnail.cgi
RUN chmod +x /usr/share/nginx/cgi-bin/thumbnail.cgi

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

CMD /entrypoint.sh && nginx -g 'daemon off;'

And if it matters here is thumbnail.cgi

#!/bin/bash
echo "Content-type: text/plain"
echo ""
echo "Hello from thumbnail.cgi script"

STREAM_NAME=$QUERY_STRING
FFMPEG_CMD="ffmpeg -i http://localhost:8080/hls/${STREAM_NAME}.m3u8 -ss 00:00:10 -vframes 1 /tmp/thumbnails/${STREAM_NAME}.png"

$FFMPEG_CMD

echo "Content-type: text/html"
echo ""
echo "<html><body><h2>Thumbnail generado para el stream ${STREAM_NAME}</h2></body></html>"

Thank in advance and sorry for my english

0

There are 0 answers