Files
notes/nginx/Build nginx from source.md
2025-12-08 05:03:52 -05:00

196 lines
4.3 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## PreRequisites
You need to install the OpenSSL development libraries as well. Here's how to fix both issues:
Install Required Dependencies
For Debian/Ubuntu systems (which you appear to be using based on the apt-get command):
```sh
sudo apt-get install libpcre3 libpcre3-dev libssl-dev
```
This command will install:
• `libpcre3` and `libpcre3-dev` - For the `PCRE library` (needed for the HTTP rewrite module)
• `libssl-dev` - For the `OpenSSL` development files (needed for SSL modules)
#### Download
1. Download latest nginx source code from [Nginx](https://nginx.org/en/download.html)
today [nginx-1.25.3](https://nginx.org/download/nginx-1.25.3.tar.gz)
2. Download RTMP Module from [github](https://github.com/arut/nginx-rtmp-module)
### Extract
1. Extract downloaded nginx
```Bash
tar zxvf nginx-1.25.3.tar.gz
```
2. change directories to extracted nginx directory
3. configure build
```Bash
./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/sbin/nginx \
--add-module=../nginx-rtmp-module
```
4. make
5. make install
### Stats
copy `stats.xsl` from `nginx-rtmp-module` to `nginx/html`
change permissions if neccessary
### nginx.conf
```
user zinn;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
chunk_size 4000;
# maps to rtmp://host:1935/radio
application radio {
# enable live streaming
live on;
# record first 1K of stream
# record all;
# record_path /tmp/av;
# record_max_size 1K;
# append current timestamp to each flv
# record_unique on;
# publish only from localhost
# deny publish all;
allow publish all;
allow play all;
}
}
}
# HTTP can be used for accessing RTMP stats
http {
server {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
listen 8080;
server_name pi-streamer;
location / {
root html;
index index.html index.htm;
}
# This URL provides RTMP statistics in XML
location /stat {
rtmp_stat all;
# Use this stylesheet to view XML as web page
# in browser
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
# XML stylesheet to view RTMP stats.
# Copy stat.xsl wherever you want
# and put the full directory path here
root html;
}
# location /hls {
# # Serve HLS fragments
# types {
# application/vnd.apple.mpegurl m3u8;
# video/mp2t ts;
# }
# root /tmp;
# add_header Cache-Control no-cache;
# }
# location /dash {
# # Serve DASH fragments
# root /tmp;
# add_header Cache-Control no-cache;
# }
}
}
```
```sh
# DID NOT WORK
ffmpeg5.1 -re -i http://10.50.90.33:5004/auto/v7.1 \
-threads 0 \
-pix_fmt yuv420p \
-vcodec libx264 \
-profile:v baseline \
-deblock 1:0 \
-bitrate 500k \
-tune zerolatency \
-x264opts keyint=30 \
-acodec aac \
-ar 48000 \
-ac 2 \
-b:a 128k \
-preset veryfast \
-crf 23 \
-bufsize 500k \
-maxrate 500k \
-hide_banner \
-loglevel info \
-f flv "rtmp://10.50.20.2:1935/ingest/channel7"
```
```sh
# Works but has pumping
ffmpeg5.1 -re -i http://10.50.90.33:5004/auto/v7.1 -threads 3 -hide_banner \
-pix_fmt yuv420p -vcodec libx264 -profile:v baseline -deblock 1:0 \
-bitrate 1000k -bufsize 1600k -maxrate 1000k \
-tune zerolatency -x264opts keyint=30 -preset veryfast \
-acodec aac -ar 48000 -ac 2 -b:a 128k \
-f flv "rtmp://10.50.20.2:1935/ingest/channel7"
```