docker部署的Nginx,怎么配置rtmp?
时间: 2024-06-08 12:05:53 浏览: 124
nginx负载均衡.txt
要在Docker上部署Nginx并配置RTMP,您需要执行以下步骤:
1. 创建一个Dockerfile:
```dockerfile
FROM nginx:latest
RUN apt-get update && apt-get install -y openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev
WORKDIR /usr/src/nginx-rtmp-module
RUN wget https://github.com/arut/nginx-rtmp-module/archive/master.zip && unzip master.zip
WORKDIR /usr/src
RUN wget http://nginx.org/download/nginx-1.21.1.tar.gz && tar -zxvf nginx-1.21.1.tar.gz
WORKDIR /usr/src/nginx-1.21.1
RUN ./configure --add-module=/usr/src/nginx-rtmp-module/nginx-rtmp-module-master
RUN make
RUN make install
RUN rm /etc/nginx/nginx.conf
COPY nginx.conf /etc/nginx/
```
2. 创建一个nginx.conf文件,其中包含RTMP服务的配置:
```nginx
worker_processes auto;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
}
}
}
http {
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
}
```
3. 构建Docker镜像:
```bash
docker build -t nginx-rtmp .
```
4. 运行Docker容器:
```bash
docker run -d -p 1935:1935 -p 80:80 nginx-rtmp
```
现在,您的Docker容器已经运行,并且RTMP服务已经在端口1935上监听。您可以使用RTMP工具(如OBS)来将视频流推送到服务器,并使用播放器(如VLC)来播放视频流。
阅读全文