Quick answer
How do I serve video from a Linux VPS with nginx and HLS?
Encode the file to HLS with ffmpeg, serve the playlists and segments with nginx using the right MIME types and cache headers, then add a certificate with certbot. At 5 Mbit/s, one viewing hour is 2.25 GB on any Noctvane plan. Flags checked against the FFmpeg and nginx documentation on 4 November 2026.
In brief
- Encode: one ffmpeg command writes 1080p and 720p renditions, their segments and a master playlist, about 3.4 GB of disk per hour of video.
- Serve: nginx needs the HLS MIME types of RFC 8216, a 5-minute cache on playlists and a 30-day cache on segments.
- Secure: allow SSH before enabling ufw, open SSH, HTTP and HTTPS, then let certbot add the certificate.
- Traffic: according to Noctvane's survey of 3 November 2026, 1 TB carries 444 viewing hours at 5 Mbit/s; Midnight states 20 TB a month.
- Limits: one origin with no failover, encoding in software, and no CDN or object storage sold by Noctvane.
What are the steps from a file to a stream?
HLS turns one video into short files and playlists that any web server can send. A player reads the playlist, picks a rendition and fetches segments one by one. Commands run as root.
Install the packages
nginx, ffmpeg, ufw, certbot and vnstat from the distribution.
Open three ports
SSH first, then HTTP and HTTPS.
Encode to HLS
One ffmpeg command writes two renditions.
Configure nginx
MIME types and cache headers.
Add HTTPS
Certbot edits the server block.
Test and embed
Read the headers, then load a player.
What do you install and open first?
Allow SSH before you enable the firewall, or you can lock yourself out. The ufw manual warns that enabling it may drop existing connections. Point the A and AAAA records of your media hostname at the server now: certbot needs them.
apt update
apt install -y nginx ffmpeg ufw certbot python3-certbot-nginx vnstat
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable
ufw status verboseHow do you encode a file to HLS with ffmpeg?
One command writes both renditions, their segments and the master playlist. Keep the source outside the web root, so that nginx can never serve it. A silent file needs the audio options removed. The 1080p rendition totals about 4.9 Mbit/s with audio, close to the 5 Mbit/s used in the Noctvane traffic arithmetic.
mkdir -p /srv/source /var/www/media/sample
# copy sample.mp4 into /srv/source, then:
cd /var/www/media/sample
nice -n 19 ffmpeg -i /srv/source/sample.mp4 \
-filter_complex "[0:v]split=2[a][b];[a]scale=-2:1080[hi];[b]scale=-2:720[lo]" \
-map "[hi]" -map 0:a:0 -map "[lo]" -map 0:a:0 \
-c:v libx264 -preset veryfast -pix_fmt yuv420p \
-force_key_frames "expr:gte(t,n_forced*6)" -sc_threshold 0 \
-b:v:0 4800k -maxrate:v:0 5300k -bufsize:v:0 9600k \
-b:v:1 2400k -maxrate:v:1 2650k -bufsize:v:1 4800k \
-c:a aac -b:a 128k -ac 2 \
-f hls -hls_time 6 -hls_playlist_type vod \
-hls_flags independent_segments \
-hls_segment_filename "%v/seg_%05d.ts" \
-master_pl_name master.m3u8 \
-var_stream_map "v:0,a:0,name:1080p v:1,a:1,name:720p" \
"%v/index.m3u8"| Option | What it does |
|---|---|
-force_key_frames, -sc_threshold 0 | A key frame every 6 seconds and none added at scene changes, so each segment starts on one |
-hls_playlist_type vod | Marks the playlist as complete and keeps every segment in it |
-var_stream_map | Groups video and audio into named renditions; %v in a path becomes the name |
The result is master.m3u8 plus 1080p/ and 720p/ folders, at about 3.4 GB of disk per hour of video. nice lowers the job's priority inside your server only. vCPU are shared with other servers on the same host, so a long encode competes for time. RAM and NVMe space are set aside for your server alone.
Which nginx settings does HLS need?
Playlists and segments need their own MIME types and very different cache lifetimes. RFC 8216 requires application/vnd.apple.mpegurl or audio/mpegurl for a playlist; video/mp2t for .ts is the mapping in nginx's mime.types. location / returns 404, so only playlists and segments are served.
expires 5m lets you replace a playlist quickly. expires 30d keeps segments in browsers and caches, so encode a changed video into a new folder. add_header is repeated because nginx drops inherited headers once a level defines its own. Set its origin to your player page, or remove the line if the player sits on the same hostname.
limit_conn_zone $binary_remote_addr zone=perip:10m;
server {
listen 80;
listen [::]:80;
server_name media.example.com;
root /var/www/media;
sendfile on;
tcp_nopush on;
limit_conn perip 20;
location / {
return 404;
}
location ~ \.m3u8$ {
types { application/vnd.apple.mpegurl m3u8; }
expires 5m;
add_header Access-Control-Allow-Origin "https://www.example.com" always;
}
location ~ \.ts$ {
types { video/mp2t ts; }
expires 30d;
limit_rate 2m;
add_header Access-Control-Allow-Origin "https://www.example.com" always;
}
}ln -s /etc/nginx/sites-available/media.example.com /etc/nginx/sites-enabled/
rm -f /etc/nginx/sites-enabled/default
nginx -t && systemctl reload nginx
certbot --nginx -d media.example.com
certbot renew --dry-run
systemctl list-timers | grep certbotlimit_rate 2m caps each request at 2 MB a second, about 17 Mbit/s, so one fast client cannot hold the port. limit_conn allows 20 connections per address; keep it generous, since many viewers can share one address. --dry-run proves that renewal works.
How do you test the stream and embed it?
Check the headers before you open a player. The playlist must answer with application/vnd.apple.mpegurl and max-age=300, a segment with video/mp2t and max-age=2592000. Safari plays HLS natively; other browsers need a script such as HLS.js.
curl -I https://media.example.com/sample/master.m3u8
curl -I https://media.example.com/sample/1080p/seg_00000.ts<video id="player" controls width="960"></video>
<script src="/js/hls.min.js"></script>
<script>
const video = document.getElementById('player');
const src = 'https://media.example.com/sample/master.m3u8';
if (Hls.isSupported()) {
const hls = new Hls();
hls.loadSource(src);
hls.attachMedia(video);
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = src;
}
</script>Where does this setup stop?
This setup is a single origin: public files on one server, with no failover. Anyone with a URL can fetch them, so paid files need the login check in how to host a creator platform.
According to Noctvane's survey of 3 November 2026, 1 TB carries 444 viewing hours at 5 Mbit/s. Compare vnstat -m with your plan, using how much bandwidth an adult video site needs. The TB figure of a plan is a stated monthly allowance, never “unmetered”. Video and live streams count like any other outbound traffic: nothing is carved out and no file type is excluded. A plan reaches the network through a 1 Gbit/s port shared with the other servers on its host.
No plan has a GPU, so encoding runs in software. Noctvane sells no CDN, no object storage and no dedicated server; check the terms of any CDN you add, because the survey read none. Backups are not part of any plan: copies of your library and your records are yours to keep elsewhere.
You remain responsible for proof of age and consent for every person filmed or photographed, for the records the law asks you to keep, and for the age verification required in each market you serve. Forbidden on every Noctvane server: content involving minors, non-consensual content, intimate images shared without consent, deepfakes of real people and trafficking. Those rules sit in the acceptable use policy.
Which other questions come up about nginx and HLS?
Why HLS instead of a plain MP4 link?
A plain file offers one quality to every viewer. HLS lets the player switch rendition as the connection changes.
Can I use this for live streams?
Not as written. A live playlist changes every few seconds, so drop -hls_playlist_type vod and the 5-minute cache.
Can I encode on another machine?
Yes, and on a busy server you should. Run the same command elsewhere and copy the folder over with rsync -av.
Was this setup run on a server?
The ffmpeg command ran on a generated test pattern on 4 November 2026: both renditions came out, each segment starting on a key frame. The nginx file was checked against nginx.org, not run, so always use nginx -t.
Verdict
- Noctvane is the better choice if one origin is enough: Midnight, at $25.87 a month on a 12-month term, holds 640 GB NVMe and states 20 TB, about 8,889 viewing hours a month.
- A CDN or a dedicated server is the better choice if peaks near 200 streams at 5 Mbit/s, because every Noctvane plan shares a 1 Gbit/s port.
Sources (11)
- FFmpeg formats: hls muxer — FFmpeg (read 2026-11-04)
- ffmpeg: -force_key_frames — FFmpeg (read 2026-11-04)
- ngx_http_core_module — nginx (read 2026-11-04)
- ngx_http_headers_module — nginx (read 2026-11-04)
- ngx_http_limit_conn_module — nginx (read 2026-11-04)
- nginx mime.types — nginx (read 2026-11-04)
- RFC 8216: HTTP Live Streaming — IETF (read 2026-11-04)
- ufw(8), Debian 13 — Debian (read 2026-11-04)
- Certbot user guide — Electronic Frontier Foundation (read 2026-11-04)
- HLS.js README — video-dev (read 2026-11-04)
- vnStat manual — vnStat (read 2026-11-04)
Run this on your own server
Midnight is $25.87 a month on a 12-month term, and Eclipse $56.25. Minutes after the payment confirms, 1 hour at the very most.
- DomaineGoat LLC · Panama
- No ID at signup: no document, no selfie
- Prices checked 3 November 2026
- Credited after network confirmations