nginx安裝-添加MP4播放模塊


nginx安裝很簡單,但是有的時候是已經安裝的nginx ,升級增加nginx 模塊功能。

最近公司要nginx增加一個可以播放 MP4的模塊,安裝還算順利,不說廢話上命令。

1 安裝依賴

yum install -y make zilb-devel openssl-devel pcre-devel libaio libaio-devel

wget http://nginx.org/download/nginx-1.10.3.tar.gz

創建用戶和用戶組

groupadd www
useradd -s /sbin/nologin -M -g www www

解壓

tar -zxvf nginx-1.10.3.tar.gz

進入nginx安裝目錄

cd nginx-1.10.3

配置 編譯安裝

./configure --user=www --group=www
--prefix=/usr/local/nginx
--with-http_stub_status_module
--with-http_ssl_module
--with-http_gzip_static_module
--with-http_gunzip_module
--with-file-aio
--with-http_flv_module
make && make install

進入nginx sbin啟動

cd /usr/local/nginx/sbin

./nginx

至此安裝完畢

下面是在原有nginx 基礎上 增加MP4播放功能模塊

首先下載 nginx_mod_h264_streaming-2.2.7.tar.gz

wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz

tar -xvf nginx_mod_h264_streaming-2.2.7.tar.gz

重點來了

vim nginx_mod_h264_streaming-2.2.7

NGINX=$(HOME)/nginx-1.10.3/ #這里修改自己的nginx版本

vim nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c

以下

TODO: Win32

if (r->zero_in_uri)

{

return NGX_DECLINED;

}

改成

/*

TODO: Win32

if (r->zero_in_uri)

{

return NGX_DECLINED;

}

*/

然后再次進入nginx的安裝目錄

cd nginx-1.10.3

./configure --user=www --group=www
--add-module=/usr/local/src/nginx_mod_h264_streaming-2.2.7
--prefix=/usr/local/nginx
--with-http_mp4_module
--with-http_flv_module
--with-http_stub_status_module
--with-http_ssl_module
--with-http_gzip_static_module
--with-http_gunzip_module
--with-file-aio
--with-http_flv_module \

注意這里只編譯 不安裝

make

修改nginx配置文件,強烈建議修改備份,我這里是直接添加nginx Vhost的方式 直接在nginx的conf 下的conf.d 下面直接添加下面的server

server {
listen 80;
server_name 你的域名;
root html;
index index.html index.htm;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
location ~.(jpg|png|gif)$ {
root /data/www/oul;
}
location ~ .*.mp4$ {
root /data/www/oul;
mp4;
}
}

注意下 這個關鍵步驟

備份您的

cd /usr/local/nginx/sbin

cp nginx nginx.bak

復制新編譯好的nginx執行文件

cp /root/cd nginx-1.10.3/objs/nginx /usr/local/nginx/sbin/nginx

找一個MP4視頻文件放到nginx網站目錄默認是/usr/local/nginx/html 下面

重啟 nginx

有個坑 ,注意修改nginx的vhost的根訪問文件夾 必須重啟 reload 不起作用!!!

另外 nginx如果增加其他功能模塊的過程大多這樣 注意 make 只編譯不要執行安裝備份還你要修改的文件


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM