Nginx Rtmp支持websocket访问吗
时间: 2024-06-08 21:07:57 浏览: 204
nginx Linux版.zip
是的,Nginx Rtmp模块是支持WebSocket访问的。可以使用WebSocket作为RTMP服务器的另一种方式,它可以在浏览器中使用JavaScript等语言进行RTMP流的播放和发布。要启用WebSocket支持,需要在Nginx配置文件中添加以下内容:
```
rtmp {
...
server {
listen 1935;
listen 8080;
chunk_size 4000;
...
location /live {
allow publish all;
allow play all;
# WebSocket support
# Requires nginx >= 1.4
# WebSocket support requires nginx RTMP module (ngx_rtmp_module)
# and nginx HTTP module (ngx_http_module)
# May require additional modules to support various browsers
# such as "nginx-module-sts" for Safari
# https://github.com/arut/nginx-rtmp-module/wiki/Directives#sts
# Also see the "ssl" directive to use WSS instead of WS
proxy_pass http://localhost:8081;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
...
}
}
```
在上面的配置示例中,我们将RTMP服务器的WebSocket支持配置在“/live”位置,并将其代理到localhost:8081。注意,启用WebSocket支持需要使用ngx_rtmp_module和ngx_http_module模块,以及可能需要其他模块来支持不同的浏览器。
阅读全文