Skip to content

Testing #36

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
venv
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ FROM alpine:3.12.0 AS base_image

FROM base_image AS build

RUN mkdir -p /var/lib/nginx/body && chmod 777 /var/lib/nginx/body

RUN apk add --no-cache curl build-base openssl openssl-dev zlib-dev linux-headers pcre-dev ffmpeg ffmpeg-dev
RUN mkdir nginx nginx-vod-module

Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,27 @@ Docker Hub
----------

The image is available on Docker Hub: https://hub.docker.com/r/nytimes/nginx-vod-module/.



chmod -R 755 $(pwd)/examples/videos

docker-compose up --build

OR

cd examples

docker run -p 3030:80 \
-v $(pwd)/videos:/opt/static/videos \
-v $(pwd)/nginx.conf:/usr/local/nginx/conf/nginx.conf \
nytimes/nginx-vod-module

http://localhost:3030/videos/

docker run -p 3030:80 \
-v $(pwd)/videos:/opt/static/videos \
-v $(pwd)/nginx.conf:/usr/local/nginx/conf/nginx.conf \
-v $(pwd)/logs:/var/log/nginx \
--entrypoint sh nytimes/nginx-vod-module -c "mkdir -p /var/lib/nginx/body && chmod 777 /var/lib/nginx/body && exec /usr/local/nginx/sbin/nginx -g 'daemon off;'"

13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.9'
services:
nginx:
image: nytimes/nginx-vod-module
container_name: nginx_vod
ports:
- "3030:80"
volumes:
- ./examples/videos:/opt/static/videos
- ./examples/nginx.conf:/usr/local/nginx/conf/nginx.conf
- ./examples/logs:/var/log/nginx
entrypoint: >
sh -c "mkdir -p /var/lib/nginx/body && chmod 777 /var/lib/nginx/body && exec /usr/local/nginx/sbin/nginx -g 'daemon off;'"
Empty file added examples/logs/access.log
Empty file.
7 changes: 7 additions & 0 deletions examples/logs/error.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
2024/12/10 08:42:24 [info] 9#9: *1 client 192.168.65.1 closed keepalive connection
2024/12/10 08:42:40 [info] 9#9: *2 client 192.168.65.1 closed keepalive connection
2024/12/10 08:43:49 [info] 9#9: *1 client 192.168.65.1 closed keepalive connection
2024/12/10 08:44:48 [info] 9#9: *1 client 192.168.65.1 closed keepalive connection
2024/12/10 08:47:33 [info] 9#9: *2 client 192.168.65.1 closed keepalive connection
2024/12/10 08:48:34 [info] 9#9: *1 client 192.168.65.1 closed keepalive connection
2024/12/10 08:51:03 [info] 9#9: *1 client 192.168.65.1 closed keepalive connection
Binary file added examples/logs/event.log
Binary file not shown.
111 changes: 45 additions & 66 deletions examples/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,72 +1,51 @@
worker_processes auto;
worker_processes auto;

events {
use epoll;
use epoll; # Эффективное управление соединениями
}

http {
log_format main '$remote_addr $remote_user [$time_local] "$request" '
'$status "$http_referer" "$http_user_agent"';

access_log /dev/stdout main;
error_log stderr debug;

default_type application/octet-stream;
include /usr/local/nginx/conf/mime.types;

sendfile on;
tcp_nopush on;
tcp_nodelay on;

vod_mode local;
vod_metadata_cache metadata_cache 16m;
vod_response_cache response_cache 512m;
vod_last_modified_types *;
vod_segment_duration 9000;
vod_align_segments_to_key_frames on;
vod_dash_fragment_file_name_prefix "segment";
vod_hls_segment_file_name_prefix "segment";

vod_manifest_segment_durations_mode accurate;

open_file_cache max=1000 inactive=5m;
open_file_cache_valid 2m;
open_file_cache_min_uses 1;
open_file_cache_errors on;

aio on;

server {
listen 80;
server_name localhost;
root /opt/static;

location ~ ^/videos/.+$ {
autoindex on;
}

location /hls/ {
vod hls;
alias /opt/static/videos/;
add_header Access-Control-Allow-Headers '*';
add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
}

location /thumb/ {
vod thumb;
alias /opt/static/videos/;
add_header Access-Control-Allow-Headers '*';
add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
}

location /dash/ {
vod dash;
alias /opt/static/videos/;
add_header Access-Control-Allow-Headers '*';
add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
}
}
# Формат логов с телом запроса
log_format custom '$remote_addr - [$time_local] "$request" $status '
'"$http_referer" "$http_user_agent" "$request_body"';

access_log /var/log/nginx/access.log custom;
error_log /var/log/nginx/error.log debug;

# Обработка тела запроса
client_body_temp_path /var/lib/nginx/body;
client_body_buffer_size 128k;
client_max_body_size 1m;

default_type application/octet-stream;
include /usr/local/nginx/conf/mime.types;

sendfile on;
tcp_nopush on;
tcp_nodelay on;

server {
listen 80;
server_name localhost;
root /opt/static;

location /videos/ {
autoindex on; # Отображение содержимого директории
alias /opt/static/videos/;
add_header Access-Control-Allow-Origin *; # Кросс-доменный доступ
}

location /log {
proxy_pass http://host.docker.internal:8080;
proxy_set_header Content-Length $content_length;
proxy_set_header Content-Type $content_type;
access_log /var/log/nginx/event.log custom;
}


location = /favicon.ico {
log_not_found off; # Не логировать отсутствие favicon
access_log off; # Не записывать запросы favicon
}
}
}
Empty file modified examples/videos/devito.en_US.vtt
100644 → 100755
Empty file.
Empty file modified examples/videos/devito360p.mp4
100644 → 100755
Empty file.
Empty file modified examples/videos/devito480p.mp4
100644 → 100755
Empty file.
Empty file modified examples/videos/devito720p.mp4
100644 → 100755
Empty file.
48 changes: 48 additions & 0 deletions examples/videos/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Video Player</title>
</head>
<body>
<h1>Video Player</h1>
<video id="video" controls width="640" height="360">
<source src="http://localhost:3030/videos/devito360p.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<!-- <video id="video2" controls width="640" height="360">-->
<!-- <source src="http://localhost:3030/videos/devito480p.mp4" type="video/mp4">-->
<!-- Your browser does not support the video tag.-->
<!-- </video>-->
<!-- <video id="video3" controls width="640" height="360">-->
<!-- <source src="http://localhost:3030/videos/devito720p.mp4" type="video/mp4">-->
<!-- Your browser does not support the video tag.-->
<!-- </video>-->

<script>
const video = document.getElementById('video');

// Логирование на паузе
video.addEventListener('pause', () => {
console.log('Video paused at:', video.currentTime);
// Отправка данных на сервер
fetch('/log', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ event: 'pause', time: video.currentTime }),
});
});

// Логирование перемотки
video.addEventListener('seeked', () => {
console.log('Video seeked to:', video.currentTime);
fetch('/log', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ event: 'seeked', time: video.currentTime }),
});
});
</script>
</body>
</html>
12 changes: 12 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from flask import Flask, request

app = Flask(__name__)

@app.route('/log', methods=['POST'])
def log():
data = request.get_json()
print(data)
return "Received", 200

if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)