1、创建nginx目录
mkdir nginx
cd nginx
wget http://nginx.org/download/nginx-1.10.3.tar.gz
wget https://codeload.github.com/arut/nginx-rtmp-module/tar.gz/v1.1.4
tar -zxvf nginx-1.10.3.tar.gz
tar -zxvf nginx-rtmp-module-1.1.4.tar.gz
cd nginx-1.10.3
./configure --add-module=../nginx-rtmp-module-1.1.4 --with-http_ssl_module
make
make install
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
nginx -V
vim /usr/local/nginx/conf/nginx.conf
ps -aux|grep nginx
nginx -s stop
nginx
curl http://192.168.20.187
curl http://192.168.20.187/stat
测试
netstat -lnp|grep 80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
curl http://192.168.20.187/stat
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="stat.xsl" ?>
<rtmp>
<nginx_version>1.10.3</nginx_version>
<nginx_rtmp_version>1.1.4</nginx_rtmp_version>
<compiler>gcc 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) </compiler>
<built>Oct 24 2020 15:37:28</built>
<pid>22111</pid>
<uptime>3533</uptime>
<naccepted>0</naccepted>
<bw_in>0</bw_in>
<bytes_in>0</bytes_in>
<bw_out>0</bw_out>
<bytes_out>0</bytes_out>
<server>
<application>
<name>rtmplive</name>
<live>
<nclients>0</nclients>
</live>
</application>
<application>
<name>vod</name>
<play>
<nclients>0</nclients>
</play>
</application>
</server>
</rtmp>
nginx.conf参考
vim /usr/local/nginx/conf/nginx.conf
#user nobody;
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;
}
http {
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;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
location /stat { #第1处添加的location字段。
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl { #第2处添加的location字段。
root /home//Downloads/nginx/nginx-rtmp-module;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
rtmp {
server {
listen 1935;
application rtmplive {
live on;
record off;
}
application vod {
play /home//Downloads/nginx/ngflvs;
}
}
}
如果编译报错:
src/core/ngx_murmurhash.c:37:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
h ^= data[2] << 16;
~~^~~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:38:5: note: here
case 2:
^~~~
src/core/ngx_murmurhash.c:39:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
h ^= data[1] << 8;
~~^~~~~~~~~~~~~~~
vim objs/Makefile
CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused -Werror -g -I../nginx-rtmp-module-1.1.4
将-Werror删掉 ps -aux|grep nginx