php - Nginx "No such file or directory error" for existing file path with appropriate permissions

796

When attempting to view the HLS stream being sent from OBS to Nginx, I keep getting the error:

33 open() "/usr/share/nginx/html/HLS/live/5cc56be78cea0.m3u8" failed (2: No such file or directory)

but the path/usr/share/nginx/html/HLS/live/ DOES exist (the stream file is also created) and I double checked the folder permissions

My Nginx config server block is:

server {

    listen 444 ssl;
    listen [::]:444 ssl;

    ssl_certificate /etc/ssl/certs/concartcert.crt;
    ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;                    

    server_name 129.567.55.36;

    location /live {
        # Disable cache
        add_header 'Cache-Control' 'no-cache';

        # CORS setup
        add_header 'Access-Control-Allow-Origin' '*' always;
        add_header 'Access-Control-Expose-Headers' 'Content-Length';

        # allow CORS preflight requests
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain charset=UTF-8';
            add_header 'Content-Length' 0;
            return 204;
        }
        types {
            application/vnd.apple.mpegurl m3u8;
        }
        alias /usr/share/nginx/html/HLS/live;
    }
    # allows us to see how stats on viewers on our Nginx site using a URL like: "http://my-ip/stats"     
    # location /stats {
        # stub_status;
    # }
    location /stat {
        rtmp_stat all;
        rtmp_stat_stylesheet stat.xsl;
    }
    location /stat.xsl {
        root html;
    }
    location /control {
        rtmp_control all;
    }
    # allows us to host some webpages which can show our videos: "http://my-ip/my-page.html"     
    location / {
        root   html;
        index  index.html index.htm;
    }   
}

Could anyone help my identify the possible cause of the error. Checking online, the two possible causes identified were the folder permissions or the folder path but after checking both I am lost on how to proceed.

501

Answer

Solution:

I would use root in the server block instead of in the location blocks and then a try_files in the location blocks, like this:

    server {

            listen 444 ssl;
            listen [::]:444 ssl;

            ssl_certificate /etc/ssl/certs/concartcert.crt;
            ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;                    

            server_name 129.567.55.36;

            root   /usr/share/nginx/html;
            index  index.html index.htm;

            location /live {
                    # Disable cache
                    add_header 'Cache-Control' 'no-cache';

                    # CORS setup
                    add_header 'Access-Control-Allow-Origin' '*' always;
                    add_header 'Access-Control-Expose-Headers' 'Content-Length';

                    # allow CORS preflight requests
                    if ($request_method = 'OPTIONS') {
                            add_header 'Access-Control-Allow-Origin' '*';
                            add_header 'Access-Control-Max-Age' 1728000;
                            add_header 'Content-Type' 'text/plain charset=UTF-8';
                            add_header 'Content-Length' 0;
                            return 204;
                    }
                    types {
                            application/vnd.apple.mpegurl m3u8;
                    }
                    try_files /HLS/live/$uri =404
            }
            #allows us to see how stats on viewers on our Nginx site using a URL like: "http://my-ip/stats"     
            #location /stats {
            #        stub_status;
            #}
            location /stat {
                    rtmp_stat all;
                    rtmp_stat_stylesheet stat.xsl;
            }
            location /control {
                    rtmp_control all;
            }
            #allows us to host some webpages which can show our videos: "http://my-ip/my-page.html"     
            location / {
                    try_files $uri $uri/ =404;
            }   
    }

If the /stat and /control URLs don't work anymore because they have another root path, you should usealias with the full path in those location blocks.

People are also looking for solutions to the problem: configure xdebug for php 7.1.28

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.