Nginx 部署流媒体服务
Nginx 平滑升级
参考地址
http://zhangge.net/4856.html
主机名 |
IP地址 |
Ngin版本 |
系统版本 |
备注 |
Nginx-Streaming-media |
192.168.1.180 |
nginx/1.9.4 |
Cenots6.6 |
V1 |
1.软件依赖环境
yum –y install gcc* make GeoI GeoIP-data GeoIP-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libxslt libxslt-devel gd gd-devel pcre-devel pcre
注释: # Libxml2是个C语言的XML程式库,能简单方便的提供对XML文件的各种操作,并且支持XPATH查询,及部分的支持XSLT转换等功能!
未安装GeoI GeoIP-data GeoIP-devel gd-devel 依赖包会出现
#编译出现以下报错信息;
出现./configure: error: the HTTP image filter module requires the GD library.
You can either do not enable the module or install the libraries.
2. NGINX源码包安装;
1.在线下载官方软件
wget http://nginx.org/download/nginx-1.9.4.tar.gz
tar xf nginx-1.*.tar.gz -C /usr/local/src
cd /usr/local/ nginx-1.9.4
2.添加编译详细参数;
./configure --prefix=/usr/loal/nginx --sbin-path=/usr/sbin/nginx --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/lock/subsys/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --http-client-body-temp-path=$nginx_tmp/client --http-proxy-temp-path=$nginx_tmp/proxy --http-fastcgi-temp-path=$nginx_tmp/fcgi --http-uwsgi-temp-path=$nginx_tmp/uwsgi --http-scgi-temp-path=$nginx_tmp/scgi --with-pcre
make && make install
3.NGINX核心配置部分
## nginx main configure file
user nginx nginx;
#worker_processes _PROCESSES;
worker_priority -10;
worker_rlimit_nofile 51200;
error_log _ERROR_LOG error;
pid /var/run/nginx.pid;
#access_log off;
#access_log /var/log/nginx/access.log combined;
events {
use epoll;
worker_connections 51200;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
charset utf-8;
server_tokens off;
server_names_hash_bucket_size 256;
client_header_buffer_size 256k;
large_client_header_buffers 4 256k;
client_max_body_size 50m;
client_body_buffer_size 256k;
client_header_timeout 3m;
client_body_timeout 3m;
sendfile on;
tcp_nopush on;
keepalive_timeout 120;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
include nginx_cache/*.conf;
}
server {
listen 80;
server_name www.test123.com;
charset utf-8;
access_log /var/log/nginx/host.access.log main;
location / {
root /home/medio/project/;
index index.html index.htm;
}
location ~ .*\.(mp4|jpg)$
{
root /home/medio/project/;
limit_rate_after 500k;
limit_rate 128k;
expires 30d;
valid_referers none blocked www.breaklinux.com breaklinux.com *.test123.com;
if ($invalid_referer) {
rewrite ^/ http://www.test123.com/retrun.html;
return 403;
}
}
}
server {
listen 80;
server_name www.wenjian123.com;
root /home/medio/test;
index index.html;
}
4. 测试流媒体服务;
上传MP4格式视频文件。放置nginx索引目录下;访问如下;
5.nginx 服务管理脚本;
#!/bin/bash
#s is nginx server manager script#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
#. /etc/rc.d/init.d/functions
# Source networking configuration.
#. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
# 这里要根据实际情况修改,实际编译安装目录
CURDIR=$(cd $(dirname ${BASH_SOURCE[0]}); pwd )
cd $CURDIR
Path=$(pwd)
nginx="$Path/sbin/nginx"
prog=$(basename $nginx)
# 这里要根据实际情况修改
NGINX_CONF_FILE="$Path/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
$nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
pkill -9 nginx
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
转载于:https://blog.51cto.com/breaklinux/2150193