之前在centos7上yum安裝了nginx,搭建了一個視頻網站,但是發現在線播放MP4視頻時無法在線播放,只能下載,查詢了相關資料,說是有一個nginx_mod_h264_streaming模塊未安裝導致,於是嘗試安裝此模塊,但是因爲是yum安裝,無configure --add-module參數,具體操作如下。
1. 先查看已安裝的nginx版本 使用nginx -V
2.下載相同版本的nginx ,解壓安裝
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar -zxvf nginx-1.12.2.tar.gz
3.備份原有配置,以免誤操作之後可以還原
cp /usr/sbin/nginx ~/nginx.back
cp -r /ect/nginx ~/nginx.conf.back
4.編譯nginx,添加模塊,根據之前nginx -V獲得的參數,再添加新的參數
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=/usr/share/nginx_mod_h264_streaming-2.2.7
以上編譯時,如出現缺少依賴,一般需要安裝以下模塊,安裝完再次編譯:
yum -y install libxml2 libxml2-dev libxslt-devel yum -y install gd-devel yum -y install perl-devel perl-ExtUtils-Embed yum -y install GeoIP GeoIP-devel GeoIP-data yum -y install pcre-devel yum -y install openssl openssl-devel
5.make
make完成後不要繼續輸入“make install”,以免現在的nginx出現問題
以上完成後,會在objs目錄下生成一個nginx文件,先驗證:
/root/nginx-1.16.1/objs/nginx -t
/root/nginx-1.16.1/objs/nginx -V
添加nginx_mod_h264_streaming模塊會報錯
在文件: h264源碼目錄/src/ngx_http_streaming_module.c
將如下部分註釋掉:
/* TODO: Win32 */
if (r->zero_in_uri)
{
return NGX_DECLINED;
}
在文件: nginx源碼目錄/objs/Makefile
刪除參數 -Werror
6. 替換Nginx文件並重啓
cp /opt/nginx-1.12.2/objs/nginx /usr/sbin/
systemctl restart nginx
7.檢查nginx nginx -V查看模塊是否已經添加