Report this

What is the reason for this report?

Nginx hls stream error

Posted on June 16, 2020

I have set up nginx with the current latest version following https://docs.peer5.com/guides/setting-up-hls-live-streaming-server-using-nginx/

I have connected successfully to the server and VCL was receiving a stream.

I left it for one week. When I returned I found I could not longer receive hls streams, or any streams.

I have tried many different pathways of installation but the most successful is still the one I followed above. Every new installation attempt falls at the hls stream pusshing from the server.

Output from nginx root folder:

total 12812
drwxr-xr-x 2 nobody   www-data    4096 Jun 16 16:04 .
drwxr-xr-x 3 www-data www-data    4096 Jun 16 15:58 ..
-rw-r--r-- 1 nobody   nogroup   837916 Jun 16 16:02 test-0.ts
-rw-r--r-- 1 nobody   nogroup   835848 Jun 16 16:02 test-1.ts
-rw-r--r-- 1 nobody   nogroup  1007116 Jun 16 16:04 test-10.ts
-rw-r--r-- 1 nobody   nogroup  1012380 Jun 16 16:04 test-11.ts
-rw-r--r-- 1 nobody   nogroup  1004860 Jun 16 16:04 test-12.ts
-rw-r--r-- 1 nobody   nogroup  1013508 Jun 16 16:04 test-13.ts
-rw-r--r-- 1 nobody   nogroup   242896 Jun 16 16:04 test-14.ts
-rw-r--r-- 1 nobody   nogroup   850512 Jun 16 16:03 test-2.ts
-rw-r--r-- 1 nobody   nogroup   826636 Jun 16 16:03 test-3.ts
-rw-r--r-- 1 nobody   nogroup   849948 Jun 16 16:03 test-4.ts
-rw-r--r-- 1 nobody   nogroup   830208 Jun 16 16:03 test-5.ts
-rw-r--r-- 1 nobody   nogroup   837540 Jun 16 16:03 test-6.ts
-rw-r--r-- 1 nobody   nogroup   902588 Jun 16 16:03 test-7.ts
-rw-r--r-- 1 nobody   nogroup  1011440 Jun 16 16:03 test-8.ts
-rw-r--r-- 1 nobody   nogroup  1012756 Jun 16 16:04 test-9.ts
-rw-r--r-- 1 nobody   nogroup      448 Jun 16 16:04 test.m3u8

So there is a stream being produced.

JW Player supplies error code 232011 - Cannot load M3U8: Crossdomain access denied

nginx conf:

worker_processes  auto;
events {
    worker_connections  1024;
}

# RTMP configuration
rtmp {
    server {
        listen 1935; # Listen on standard RTMP port
        chunk_size 4000;

        application show {
            live on;
            # Turn on HLS
            hls on;
            hls_path /nginx/hls/;
            hls_fragment 3;
            hls_playlist_length 60;
            # disable consuming the stream from nginx as rtmp
            deny play all;
        }
    }
}

http {
    sendfile off;
    tcp_nopush on;
    # aio on;
    directio 512;
    default_type application/octet-stream;

    server {
        listen 8080;

        location / {
            # 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/dash+xml mpd;
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }

            root /nginx/;
        }
    }
}

Can anyone assist in identifying the error please?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

The error message “Cannot load M3U8: Crossdomain access denied” is a common issue with JW Player when it’s not served from the same domain as the web page and is restricted due to the same-origin policy.

However, you already have CORS headers setup in your nginx configuration. Your configuration seems fine and should theoretically allow cross-origin requests.

But it looks like JW Player isn’t able to access the M3U8 file due to a cross-domain issue. A couple of things you could try:

  1. Make sure your CORS setup is correct and is being applied: The CORS headers must be returned in the response from the server for the JW Player to be able to play the content. Check the response headers of your M3U8 file by using the developer tools in your browser or using a tool like curl -I to see the response headers. If the CORS headers aren’t there, your nginx configuration might not be applied correctly.

  2. Check if your content is served over HTTPS while your page is on HTTP or vice versa: JW Player requires the page and the content to be served over the same protocol (both HTTP or both HTTPS). Make sure this is not the issue.

  3. Crossdomain.xml: Even though CORS is the modern way to handle cross-origin requests, Flash players might still need a crossdomain.xml file served from the root of the server. You might need to add this if your JW Player falls back to Flash player for some reason.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.