Nginx

/etc/nginx/nginx.conf 中的未知指令“rtmp”

  • May 14, 2022

我的作業系統資訊:

uname -a
Linux vultr 5.10.0-13-amd64 #1 SMP Debian 5.10.106-1 (2022-03-17) x86_64 GNU/Linux

我已經libnginx-mod-rtmp用命令安裝了模組

apt install libnginx-mod-rtmp

你可以看到輸出資訊:

Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /lib/systemd/system/nginx.service.
Setting up libnginx-mod-http-xslt-filter (1.18.0-6.1) ...
Setting up libnginx-mod-http-geoip (1.18.0-6.1) ...
Setting up libnginx-mod-rtmp (1.18.0-6.1) ...
Setting up libnginx-mod-mail (1.18.0-6.1) ...
Setting up libnginx-mod-http-image-filter (1.18.0-6.1) ...
Setting up libnginx-mod-stream (1.18.0-6.1) ...
Setting up libnginx-mod-stream-geoip (1.18.0-6.1) ...
Setting up nginx-core (1.18.0-6.1) ...
Upgrading binary: nginx.
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for ufw (0.36-7.1) ...

現在在配置文件中設置 rmtp。

vim /etc/nginx/nginx.conf
rtmp {
       server {
               listen 1935;
               chunk_size 4096;
               allow publish 127.0.0.1;
               deny publish all;

               application live {
                       live on;
                       record off;
               }
       }
}

重啟 nginx。

systemctl restart  nginx
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
    Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Drop-In: /etc/systemd/system/nginx.service.d
            └─override.conf
    Active: failed (Result: exit-code) since Wed 2022-05-04 08:14:19 CST; 16s ago
      Docs: man:nginx(8)
   Process: 96329 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
       CPU: 7ms

May 04 08:14:19 vultr systemd[1]: Starting A high performance web server and a reverse proxy server...
May 04 08:14:19 vultr nginx[96329]: nginx: [emerg] unknown directive "rtmp" in /etc/nginx/nginx.conf:85
May 04 08:14:19 vultr nginx[96329]: nginx: configuration file /etc/nginx/nginx.conf test failed
May 04 08:14:19 vultr systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
May 04 08:14:19 vultr systemd[1]: nginx.service: Failed with result 'exit-code'.
May 04 08:14:19 vultr systemd[1]: Failed to start A high performance web server and a reverse proxy server.

nginx -V
nginx version: nginx/1.18.0
built with OpenSSL 1.1.1k  25 Mar 2021 (running with OpenSSL 1.1.1n  15 Mar 2022)
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -ffile-prefix-map=/build/nginx-q9LD4J/nginx-1.18.0=. 
                    -fstack-protector-strong -Wformat -Werror=format-security 
                    -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' 
                    --with-ld-opt='-Wl,-z,relro -Wl,-z,now -fPIC' 
                    --prefix=/usr/share/nginx 
                    --conf-path=/etc/nginx/nginx.conf 
                    --http-log-path=/var/log/nginx/access.log 
                    --error-log-path=/var/log/nginx/error.log 
                    --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid 
                    --modules-path=/usr/lib/nginx/modules 
                    --http-client-body-temp-path=/var/lib/nginx/body 
                    --http-fastcgi-temp-path=/var/lib/nginx/fastcgi 
                    --http-proxy-temp-path=/var/lib/nginx/proxy 
                    --http-scgi-temp-path=/var/lib/nginx/scgi 
                    --http-uwsgi-temp-path=/var/lib/nginx/uwsgi 
                    --with-compat --with-debug --with-pcre-jit 
                    --with-http_ssl_module --with-http_stub_status_module 
                    --with-http_realip_module 
                    --with-http_auth_request_module 
                    --with-http_v2_module --with-http_dav_module 
                    --with-http_slice_module --with-threads 
                    --with-http_addition_module 
                    --with-http_gunzip_module --with-http_gzip_static_module 
                    --with-http_sub_module

如何解決問題?

起初我以為你必須建構包含模組的 nginx,但通過 apt install 進行時似乎不需要。

您可能必須手動載入模組(檢查模組是否存在於模組目錄中):

load_module "modules/ngx_rtmp_module.so";

我見過的另一個目錄提到:

load_module /usr/local/libexec/nginx/ngx_rtmp_module.so;

引用自:https://serverfault.com/questions/1100084