Where Nginx does better than SRS

In the nginx.org document, an excerpt from nginx's article, Chapter "nginx" in "The Architecture of Open Source Applications" , is excerpted . This article is very good. Read it together:

  • 14.1. Why Is High Concurrency Important? Introduces what problems Nginx solves, and why Apache cannot solve these problems.
  • 14.2. Overview of nginx Architecture introduces the Nginx module architecture, the relationship between upstream and downstream, Cache, Worker model.
  • 14.3. Nginx Configuration Talk about the logic of configuration. I didn't expect that there will be a special chapter on configuration in Nginx.
  • 14.4. Nginx Internals is mainly about Nginx Modules. The core of Nginx is mainly to provide the functions of web server, web and mail proxy. The main function is completed by the combination of modules and module pipeline or chain, which is divided into event modules, phase handlers, output filters, variable handlers, protocols, upstreams and load balancers and many more.
  • 14.5. Lessons Learned  there is always room for improvement, the wheel of history always moves forward and never stops.
 
@winlinvip  winlinvip added this to the  SRS 4.0 release milestone  on 14 Jan
@winlinvip
 
MemberAuthor

winlinvip commented on 14 Jan

Nginx's rewrite module is a module that rewrites the path. You can see that nginx is in the configuration. In addition to using PCRE to support regular expressions, you can also configure more complicated processes. For example, if can rewrite the path under different conditions:

if ($http_user_agent ~ MSIE) {
    rewrite ^(.*)$ /msie/$1 break;
}

if ($http_cookie ~* "id=([^;]+)(?:;|$)") {
    set $id $1;
}

if ($request_method = POST) {
    return 405;
}

if ($slow) {
    limit_rate 10k;
}

if ($invalid_referer) {
    return 403;
}

This is equivalent to parsing part of the logic. In addition to openresty supporting the Lua extension language, Nginx also supports njs, which is javascript.

SRS will not support scripting languages. Currently, HTTP (S) is a common language between systems. I think HTTP integration is a more appropriate method. Of course, Nginx has done a very good job in configuration and script extension language, which is worthy of admiration and learning.

@winlinvip
 
MemberAuthor

winlinvip commented on 16 Jan • 

edited 

Nginx can support WebSocket proxy, please refer to WebSocket proxying .

As a chestnut, convert the live HTTP-FLV stream http://localhost:8082/live/livestream.flv, use videojs-flow into a WebSocket stream ws://localhost:8081/live/livestream.flv, and then use Nginx proxy ws://localhost:8080/live/livestream.flv.

The SRS configuration is as follows:

listen              1935;
max_connections     1000;
daemon              off;
srs_log_tank        console;
http_server {
    enabled         on;
    listen          8082;
}
vhost __defaultVhost__ {
    http_remux {
        enabled     on;
        mount       [vhost]/[app]/[stream].flv;
    }
    ingest livestream {
        enabled      on;
        input {
            type    file;
            url     ./doc/source.200kbps.768x320.flv;
        }
        ffmpeg      ./objs/ffmpeg/bin/ffmpeg;
        engine {
            enabled          off;
            output          rtmp://127.0.0.1:[port]/live?vhost=[vhost]/livestream;
        }
    }
}

Start videojs-flow / demo / mse.go and convert HTTP-FLV to WS-FLV:

go get golang.org/x/net/websocket &&
go run mse.go -l 8081 -b 8082

Configure Nginx, reverse proxy WS-FLV is as follows:

daemon off;
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    server {
        listen       8080;
        location / {
            proxy_pass http://localhost:8081;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
}

Use bilibili / flv.js to play the stream address:ws://localhost:8080/live/livestream.flv

image

Guess you like

Origin www.cnblogs.com/xiami2046/p/12758346.html