Nginx: Streaming with RTMP / DASH / HLS
Aus QBWiki
Version vom 12. Juni 2022, 13:40 Uhr von Pascal (Diskussion | Beiträge)
1 apt install iptables-persistent wget curl iptraf-ng dnsutils git build-essential ffmpeg libpcre3 libpcre3-dev libssl-dev zlib1g-dev dehydrated vim
2 mkdir -p /var/www
3
4 # Iptables
5 iptables -A INPUT -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
6 iptables -A INPUT -p udp -m state --state RELATED,ESTABLISHED -j ACCEPT
7 iptables -A INPUT -i lo -j ACCEPT
8 iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
9 iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
10 iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
11 iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 1935 -j ACCEPT
12 iptables -A INPUT -p icmp -m icmp --icmp-code 0 -j ACCEPT
13 iptables -A INPUT -p icmp -m icmp --icmp-code 3 -j ACCEPT
14 iptables -A INPUT -p icmp -m icmp --icmp-code 8 -j ACCEPT
15 iptables -P INPUT DROP
16 iptables -P FORWARD DROP
17 iptables-save > /etc/iptables/rules.v4
18
19 hostname -f > /etc/dehydrated/domains.txt
20 sed -i -e 's/WELLKNOWN.*/WELLKNOWN=\/var\/www\/acme-challenge/g' /etc/dehydrated/config
21
22 working_dir="/opt"
23
24 # Create Nginx User
25 adduser --system --no-create-home --shell /bin/false --group --disabled-login nginx
26
27 # Create Nginx directories:
28 mkdir -p /etc/nginx
29 mkdir -p /var/log/nginx
30 mkdir -p /run/nginx
31 mkdir -p /var/cache/nginx
32
33 # Permissions
34 chown -R nginx:nginx /etc/nginx
35 chown -R nginx:nginx /var/log/nginx
36 chown -R nginx:nginx /run/nginx
37 chown -R nginx:nginx /var/cache/nginx
38
39 cd "${working_dir}"
40
41 git clone https://github.com/arut/nginx-rtmp-module.git
42 git clone https://github.com/nginx/nginx.git
43
44 cd "${working_dir}/nginx"
45 mv "${working_dir}/nginx/auto/configure" "${working_dir}/nginx"
46 chmod +x "${working_dir}/nginx/configure"
47
48 arg_chain='--prefix=/etc/nginx --sbin-path=/usr/sbin --conf-path=/etc/nginx/nginx.conf --pid-path=/run/nginx/nginx.pid --lock-path=/run/nginx/nginx.lock --error-log-path=/var/log/nginx/error.log --user=nginx --group=nginx --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_gunzip_module --with-debug --add-module=/opt/nginx-rtmp-module --http-client-body-temp-path=/var/cache/nginx/client_body_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --http-log-path=/var/log/nginx/access.log'
49
50 ./configure ${arg_chain}
51
52 # NGINX-RTMP-ERROR beheben (OBSOLET)
53 #linenum="$(grep -Rn 'case ESCAPE' /opt/nginx-rtmp-module/ngx_rtmp_eval.c |awk -F':' '{print $1}')"
54 #insertnum="$(($linenum - 1 ))"
55 #
56 #sed -i "${insertnum} a /* fall through */" /opt/nginx-rtmp-module/ngx_rtmp_eval.c
57
58 make -j`nproc`
59 make install
60
61 # Systemd Service-file
62
63 tee /usr/lib/systemd/system/nginx.service <<EOF
64 [Unit]
65 Description=A high performance web server and a reverse proxy server
66 After=network.target
67
68 [Service]
69 Type=forking
70 PIDFile=/run/nginx/nginx.pid
71 ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
72 ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
73 ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
74 ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
75 TimeoutStopSec=5
76 KillMode=mixed
77
78 [Install]
79 WantedBy=multi-user.target
80 EOF
81
82
83 systemctl daemon-reload
84 systemctl enable nginx
85
86 mv /etc/nginx /etc/default.nginx
87 mkdir -p /etc/nginx/{conf.d,rtmp.d,}
88 chown -R nginx:nginx /etc/nginx
89
90 systemctl start nginx