Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advantages of Nginx over SRS #1576

Closed
winlinvip opened this issue Jan 14, 2020 · 4 comments
Closed

Advantages of Nginx over SRS #1576

winlinvip opened this issue Jan 14, 2020 · 4 comments
Assignees
Labels
TransByAI Translated by AI/GPT.
Milestone

Comments

@winlinvip
Copy link
Member

winlinvip commented Jan 14, 2020

Learn where Nginx performs better than SRS and the areas worth studying.

TRANS_BY_GPT3

@winlinvip
Copy link
Member Author

winlinvip commented Jan 14, 2020

In the nginx.org documentation, an article introducing nginx is excerpted. The article is titled Chapter "nginx" in "The Architecture of Open Source Applications", and it is written very well. Let's 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 explains Nginx's module architecture and its relationship with upstream and downstream, Cache, and Worker model.
  • 14.3. nginx Configuration discusses the logic of configuration, unexpectedly there is a dedicated chapter for configuration in Nginx.
  • 14.4. nginx Internals mainly covers Nginx Modules. Nginx's core primarily provides web server, web and mail proxy functionalities, which are achieved through the combination of modules and module pipelines or chains. It includes event modules, phase handlers, output filters, variable handlers, protocols, upstreams, and load balancers, among others.
  • 14.5. Lessons Learned there is always room for improvement, the wheels of history always keep rolling forward without stopping.

TRANS_BY_GPT3

@winlinvip winlinvip added this to the SRS 4.0 release milestone Jan 14, 2020
@winlinvip
Copy link
Member Author

winlinvip commented Jan 14, 2020

The rewrite module of Nginx is a module that allows rewriting paths. In the configuration of Nginx, it can be seen that besides supporting regular expressions with PCRE, it can also configure complex processes. For example, the "if" statement can rewrite paths 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 already equivalent to parsing some logic. Besides supporting the Lua extension language in OpenResty, Nginx also supports njs, which is JavaScript.

SRS does not support scripting languages. Currently, HTTP(S) serves as the common language between systems, and I believe integrating with HTTP is a more suitable approach. However, Nginx has done an excellent job in terms of configuration and scripting language extensions, which is admirable and worth learning from.

TRANS_BY_GPT3

@winlinvip
Copy link
Member Author

winlinvip commented Jan 16, 2020

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

For example, to convert a live HTTP-FLV stream http://localhost:8082/live/livestream.flv into a WebSocket stream ws://localhost:8081/live/livestream.flv using videojs-flow, and then proxy it with Nginx to 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 to convert HTTP-FLV to WS-FLV.

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

Configure Nginx to reverse proxy WS-FLV 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

TRANS_BY_GPT3

@winlinvip
Copy link
Member Author

winlinvip commented Dec 1, 2020

Almost all SRS have been completed.

TRANS_BY_GPT3

@winlinvip winlinvip self-assigned this Sep 5, 2021
@winlinvip winlinvip changed the title Nginx比SRS做得好的地方 Advantages of Nginx over SRS Jul 28, 2023
@winlinvip winlinvip added the TransByAI Translated by AI/GPT. label Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TransByAI Translated by AI/GPT.
Projects
None yet
Development

No branches or pull requests

1 participant