AdminsForum

aaPanel Websites & Web Servers Guides

Guide How to Install an NGINX-Based Media Streaming Server

Started by ALEX 0 replies 214 views
1ALEX
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
#1
nginx rtmp media server adminsforum   
You can run an NGINX-based RTMP/HLS media server on an aaPanel VPS without replacing the Nginx binary that serves your websites. This guide builds a separate streaming process, publishes a generated test video and verifies the HLS output. It is a localhost lab installation, not an Internet-facing streaming service.

What you will build
FFmpeg sends H.264 video and AAC audio to an RTMP application called live. The module creates a changing .m3u8 playlist and .ts video segments. An HTTP listener serves those files to an HLS-capable player. RTMP is the ingest connection; HLS is the playback format. An ordinary browser does not play an rtmp:// URL as an HTML video.

Tested environment
Ubuntu 22.04, aaPanel server, Nginx 1.30.6 compiled separately, nginx-rtmp-module commit 6c7719d0ba32e00b563ec70bd43dad11960fa9c4 and FFmpeg 4.4.2. The existing aaPanel Nginx was 1.30.5. We also checked module compilation against 1.30.5. No aaPanel Nginx binary was overwritten.

1. Check prerequisites and ports
Use a disposable Linux lab with SSH/root access, a backup, free disk space and a compiler. A domain is not needed for this localhost test. Commands below assume a root shell; do not paste a root prompt as part of the command.
Code:
id cat /etc/os-release df -h / /www/server/nginx/sbin/nginx -V 2>&1 ss -lntH '( sport = :11935 or sport = :18085 )' getent passwd www
The port check should print no listeners. Stop if either port is occupied; do not kill an unfamiliar service. This example uses aaPanel's existing www account. Confirm it exists before proceeding.

Install build dependencies from Ubuntu's repositories if missing:
Code:
apt-get update apt-get install --no-install-recommends build-essential libpcre3-dev libssl-dev zlib1g-dev git curl ffmpeg
Build tools and headers were already present in our lab; FFmpeg was added for the test. Review the package manager's proposed changes before accepting them.

2. Download and pin the source
Keep these variables in the same SSH shell. The dated names identify this example's isolated directories; use fresh empty directories for your own lab.
Code:
RTMP_WORK=/root/adminsforum-rtmp-review-20261019 RTMP_PREFIX=/opt/adminsforum-rtmp-lab-20261019 mkdir -p "$RTMP_WORK" cd "$RTMP_WORK" git clone https://github.com/arut/nginx-rtmp-module.git git -C nginx-rtmp-module checkout --detach 6c7719d0ba32e00b563ec70bd43dad11960fa9c4 curl -fL https://nginx.org/download/nginx-1.30.6.tar.gz -o nginx-1.30.6.tar.gz sha256sum nginx-1.30.6.tar.gz tar -xzf nginx-1.30.6.tar.gz
Record the source version, commit and download hash with your change notes. The hash records the downloaded bytes; it is not an independent signature verification. These versions reproduce our test; check current security releases before deploying publicly.

3. Fix the configure-directory mistake and build
The older aaPanel forum recipe ends its prefix script with ./configure after changing only to /www/server/nginx/src. That is not a complete Nginx build workflow. The RTMP repository supplies a config file, not its own configure executable. Run Nginx's configure from the extracted Nginx source directory and pass the module's absolute path:
Code:
cd "$RTMP_WORK/nginx-1.30.6" ./configure --prefix="$RTMP_PREFIX" --with-http_ssl_module --add-module="$RTMP_WORK/nginx-rtmp-module" make -j2 ./objs/nginx -V 2>&1
Stop on a configure or make error. The version output should include --add-module followed by the RTMP source path. This uses a static add-module build. It does not create a module .so to load into your existing aaPanel Nginx.

Do not run make install against /www/server/nginx. Copy only the newly built binary into the separate prefix:
Code:
install -d -m 0755 "$RTMP_PREFIX/sbin" "$RTMP_PREFIX/conf" install -m 0755 objs/nginx "$RTMP_PREFIX/sbin/nginx" for d in logs hls client_body_temp proxy_temp fastcgi_temp uwsgi_temp scgi_temp; do install -d -o www -g www -m 0750 "$RTMP_PREFIX/$d" done
Keep the binary and configuration owned by root. Only runtime directories need to be writable by www. The process will run as www rather than a root streaming worker.

4. Create the isolated streaming configuration
Save the following complete file as /opt/adminsforum-rtmp-lab-20261019/conf/nginx.conf, for example with nano. If you chose another prefix, update both absolute hls paths too. Keep the rtmp block at the top level, alongside http; do not paste it into an aaPanel website's server block.
Code:
worker_processes 1; pid logs/nginx.pid; error_log logs/error.log info; events { worker_connections 128; } rtmp { server { listen 127.0.0.1:11935; application live { live on; record off; allow publish 127.0.0.1; deny publish all; allow play 127.0.0.1; deny play all; hls on; hls_path /opt/adminsforum-rtmp-lab-20261019/hls; hls_fragment 2s; hls_playlist_length 8s; } application denied { live on; deny publish all; deny play all; } } } http { access_log logs/access.log; default_type application/octet-stream; server { listen 127.0.0.1:18085; server_name localhost; location /hls/ { alias /opt/adminsforum-rtmp-lab-20261019/hls/; types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } add_header Cache-Control "no-store" always; autoindex off; } location = /stat { rtmp_stat all; } location / { return 404; } } }
Port 11935 is RTMP ingest; 18085 serves HLS/statistics. Both bind to 127.0.0.1. The live application permits localhost publishing/playback only. The denied application deliberately rejects publishing for a negative test. No external command hooks or recording are enabled.

5. Validate, start and inspect
Code:
runuser -u www -- "$RTMP_PREFIX/sbin/nginx" -p "$RTMP_PREFIX/" -c conf/nginx.conf -t runuser -u www -- "$RTMP_PREFIX/sbin/nginx" -p "$RTMP_PREFIX/" -c conf/nginx.conf ss -lntp | grep -E '11935|18085' curl -sS http://127.0.0.1:18085/stat
Run the start command only after the configuration test succeeds. Confirm the listeners say 127.0.0.1, not 0.0.0.0 or [::]. The XML statistics response should identify nginx_rtmp_version and the live application. An idle application has no publisher yet.

6. Publish a short synthetic stream
This generates a small test picture and tone without using copyrighted sample media or a camera. Leave it running while you inspect the output from a second SSH session:
Code:
ffmpeg -hide_banner -loglevel error -re -f lavfi -i testsrc2=size=320x180:rate=10 -f lavfi -i sine=frequency=440:sample_rate=44100 -t 30 -c:v libx264 -preset ultrafast -tune zerolatency -threads 1 -pix_fmt yuv420p -g 20 -c:a aac -b:a 64k -f flv rtmp://127.0.0.1:11935/live/test
-re paces the generated input; -t limits the test; libx264/AAC select the video/audio encoders. Ten frames per second with -g 20 gives a two-second keyframe interval for this fixture. The URL selects application live and stream name test. This is a modest functional test, not a capacity benchmark.

7. Verify the playlist and video segments
While the publisher is active, wait for several seconds and run:
Code:
curl -i http://127.0.0.1:18085/hls/test.m3u8 ls -lh /opt/adminsforum-rtmp-lab-20261019/hls/ curl -sS http://127.0.0.1:18085/stat
Expect HTTP 200, Content-Type: application/vnd.apple.mpegurl, Cache-Control: no-store and a playlist beginning #EXTM3U. Look for an actual segment name such as test-0.ts. Download the segment name currently listed, rather than assuming an old segment is still present:
Code:
curl -f http://127.0.0.1:18085/hls/test-0.ts -o /tmp/af-stream-test.ts ffprobe -v error -show_entries stream=codec_name,codec_type,width,height -of json /tmp/af-stream-test.ts ffmpeg -v error -i /tmp/af-stream-test.ts -f null -
Replace test-0.ts if the current playlist lists another segment. Our lab returned a 99,640-byte segment, H.264 320x180 video and AAC audio; decoding exited successfully with no decoder errors. The separate denied application rejected a test publisher. An HLS playlist can return 404 until the first segment exists, and old live segments may disappear after the publisher stops.

8. Access the private test from your own computer
For a player test, an SSH local tunnel can forward the localhost HTTP listener:
Code:
ssh -N -L 18085:127.0.0.1:18085 YOUR_SSH_USER@YOUR_VPS_IP
Keep the tunnel open and use http://127.0.0.1:18085/hls/test.m3u8 in an HLS-capable player while publishing. For OBS ingest, a second tunnel can forward port 11935; the server field is rtmp://127.0.0.1:11935/live and stream key is test. These desktop-player/OBS steps are follow-up instructions, not completed tests in our evidence. We verified the generated HLS segment using FFmpeg on the server.

9. Troubleshoot by symptom
  • No such file ./configure: enter the extracted Nginx source directory; do not execute configure inside the RTMP repository or a generic parent src directory.
  • Unknown directive rtmp: verify you are using the newly built binary and that -V shows the module. The ordinary aaPanel binary is a different executable.
  • rtmp directive is not allowed here: move the block to the main configuration level, outside http/server/location.
  • Address already in use: inspect ss output and choose unused lab ports; do not stop the website server to free port 80.
  • HLS 404: confirm the publisher is active, its application/name match live/test, hls is enabled, and www can write the configured hls directory.
  • Permission denied: inspect logs/error.log and directory permissions; avoid chmod 777.
  • Audio/video missing: inspect FFmpeg output, keyframe spacing and actual segment codecs instead of assuming a successful connection means playable media.
  • Works locally but not remotely: localhost binding is intentional. A public streaming deployment needs its own access-control, HTTPS and firewall design.

10. Stop and roll back this lab
Stop the publisher with Ctrl+C, then stop only this instance:
Code:
runuser -u www -- /opt/adminsforum-rtmp-lab-20261019/sbin/nginx -p /opt/adminsforum-rtmp-lab-20261019/ -c conf/nginx.conf -s quit ss -lntH '( sport = :11935 or sport = :18085 )' /www/server/nginx/sbin/nginx -t
The dedicated ports should disappear; the aaPanel website configuration should still validate. We tested this stop operation. Keep the isolated files/logs for review; no shared website configuration needs restoring. The example does not install a boot service, so it does not auto-start after reboot.

What is still needed for public broadcasting?
A public deployment needs publisher authentication, protected statistics/control endpoints, valid playback HTTPS, monitored disk/bandwidth usage, a supervised service and realistic load tests. A stream name alone is not authentication. This article deliberately keeps the test private; it does not claim public OBS access, browser playback, CDN delivery, RTMPS or a production security audit.

About aaPanel's Add Module screen
The native panel approach recompiles its managed Nginx and must preserve all existing build options and update behavior. We did not perform that replacement on this working server. The corrected principle is to prepare the RTMP source in the prefix script, provide --add-module with its absolute path, and let the Nginx build run configure. Do not copy the older recipe's stray ./configure into that prefix script. A native-panel rebuild deserves a separate disposable-server test.

References: original aaPanel discussion, module source, official Nginx downloads. All diagrams and test media in this article are original AdminsForum lab material.
Reply
Possibly Related Threads…matched by title
Replies:0Views:80
Replies:0Views:178
Replies:0Views:197
Replies:0Views:216
Replies:0Views:205

Users browsing this thread: 4 Guest(s)
Forum Jump: