Allan Tori
Allan Tori

Reputation: 11

Nginx hls with authentication

I have a Nginx installation in Formath HLS, I would like to add authentication to read the HLS flow, as for the RTMP flow with "Play_on 127.0.0.1/auth", which worked with the configuration:

location /auth {
         if ($arg_pwd = 'secretPassword') {
        return 201;
        }
        return 404;
        }
        location /hls {
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }

who read it with a link like: rtmp://URL:1935/live/stream?pwd=secretPassword. All this worked very well on the server, but with HTML5 this is finished So I would like to do the same thing in HLS, I tried a lot of test without success

My last test: nginx.conf:

rtmp {
    access_log /var/log/nginx/rtmp_access.log;
    
    server {
        listen 1935;
        notify_method get;
        chunk_size 4096;
        #stream1
        application live {
            live on;            
            allow publish 127.0.0.1;
            deny publish all;
            on_play http://127.0.0.1:8959/auth;
            record off;
            allow play 127.0.0.1;
            allow play all;

/etc/nginx/sites-enabled/default:

        location = /auth {                                                                          
        internal;
        proxy_pass    http://127.0.0.1:8959/auth;
        proxy_pass_request_body off;
        proxy_set_header        Content-Length "";
        proxy_set_header        X-Original-URI $request_uri;               
        }
        
    location /auth {
         if ($arg_pwd = 'fFtyWz489gt') {
        return 201;
        }
        return 404;
        }
        location /hls {
            auth_request  /auth;
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
             root /data/hls;
            add_header Cache-Control no-cache;
            add_header 'Access-Control-Allow-Origin' '*';
        }

But I still have in Error.log:

[error] 1561761#1561761: *5 auth request unexpected status: 404 while sending to client, client: XX.XXX.XXX.XX, server: localhost, request: "GET /hls1/STREAM/index.m3u8?pwd=secretPassword HTTP/1.0", host: "URL:8959"

et en access.log:

 [04/Jun/2024:22:37:51 +0200] "GET /hls1/stream/index.m3u8?pwd=secretPassword HTTP/1.0" 500 537 "-" "VLC/3.0.20 LibVLC/3.0.20"

Test done on VLC: http://URLserver:8959/hls1/stream/index.m3u8?pwd=secretPassword

If someone has managed to make HLS stream work with authentication with password, this will be a great help and move forward, I saw a lot here and elsewhere but I feel like nobody really is arrived?

Upvotes: 0

Views: 63

Answers (0)

Related Questions