dongyue3795 2019-04-28 13:36
浏览 131

对于具有适当权限的现有文件路径,Nginx“没有此类文件或目录错误”

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.

  • 写回答

1条回答 默认 最新

  • dqba94394 2019-04-28 13:50
    关注

    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 use alias with the full path in those location blocks.

    评论

报告相同问题?