Skip to content

Instantly share code, notes, and snippets.

@jamesnguyen101
Created June 29, 2018 03:25
Show Gist options
  • Save jamesnguyen101/a63064acb7fb12fa1fa0dece20c98db2 to your computer and use it in GitHub Desktop.
Save jamesnguyen101/a63064acb7fb12fa1fa0dece20c98db2 to your computer and use it in GitHub Desktop.
Install nginx with nginx-tmp-module from source
#!/bin/sh
# set -e
#to remove trailing \r character
#sed -i 's/\r$//' file_name.sh or using dos2unix to format: yum install dos2unix -y
#Nginx from source
#http://www.ehowstuff.com/how-to-install-nginx-on-centos-7-rhel-7/
#
#Note: enable AIO
# Nginx RTMP Module
#https://github.com/arut/nginx-rtmp-module
################################################################################################
NGINX_VERSION=1.14.0
NGINX_DIR=/opt/nginx
NGINX_USER=nginx
echo "############### install Nginx with RTMP Module"
## package required
yum -y install gcc gcc-c++ make zlib-devel pcre-devel openssl-devel libatomic_ops-devel
yum -y install libxml2-devel libxslt-devel gd-devel perl-ExtUtils-Embed GeoIP-devel gperftools-devel
yum -y install libaio-devel libvpx-devel
## create nginx directory structure if it's not exist
mkdir -p $NGINX_DIR
mkdir -p $NGINX_DIR/conf.d
mkdir -p $NGINX_DIR/logs
mkdir -p $NGINX_DIR/cache
mkdir -p $NGINX_DIR/modules
##########################################################
cd $NGINX_DIR
##github: @/arut/nginx-rtmp-module
wget -O nginx-rtmp-module.zip https://codeload.github.com/arut/nginx-rtmp-module/zip/master
unzip nginx-rtmp-module.zip
mv nginx-rtmp-module-master nginx-rtmp-module
## download and build
wget http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz
tar xfz nginx-$NGINX_VERSION.tar.gz
cd nginx-$NGINX_VERSION/
echo "############### run ./configure "
./configure \
--prefix=$NGINX_DIR \
--modules-path=$NGINX_DIR/modules \
--sbin-path=$NGINX_DIR/sbin/nginx \
--conf-path=$NGINX_DIR/nginx.conf \
--error-log-path=$NGINX_DIR/logs/error.log \
--http-log-path=$NGINX_DIR/logs/access.log \
--pid-path=$NGINX_DIR/nginx.pid \
--lock-path=$NGINX_DIR/nginx.lock \
--http-client-body-temp-path=$NGINX_DIR/cache/client_temp \
--http-proxy-temp-path=$NGINX_DIR/cache/proxy_temp \
--http-fastcgi-temp-path=$NGINX_DIR/cache/fastcgi_temp \
--http-uwsgi-temp-path=$NGINX_DIR/cache/uwsgi_temp \
--http-scgi-temp-path=$NGINX_DIR/cache/scgi_temp \
--with-http_ssl_module \
--with-select_module \
--with-http_realip_module \
--with-http_addition_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_stub_status_module \
--with-http_auth_request_module \
--with-http_xslt_module \
--with-mail \
--with-mail_ssl_module \
--with-http_perl_module \
--with-poll_module \
--with-threads \
--with-file-aio \
--with-stream \
--with-http_image_filter_module \
--with-http_geoip_module \
--with-http_degradation_module \
--with-pcre \
--with-google_perftools_module \
--with-debug \
--add-module=../nginx-rtmp-module
make
make install
echo "############### Installation successfully"
echo "############### Create default nginx config file"
tee "$NGINX_DIR/nginx.conf" <<END
#user nginx;
worker_processes auto;
#worker_processes 4;
#worker_cpu_affinity 0001 0010 0100 1000;
events {
worker_connections 1024;
}
#error_log $NGINX_DIR/logs/error.log debug;
error_log $NGINX_DIR/logs/error.log notice;
#error_log $NGINX_DIR/logs/error.log info;
# RTMP configuration
rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
include $NGINX_DIR/conf.d/*.conf;
include $NGINX_DIR/conf.d/**/*.conf;
}
}
END
echo "############### Remove all assets not use"
cd $NGINX_DIR
rm -r nginx-$NGINX_VERSION
rm -r nginx-$NGINX_VERSION*
rm -r nginx-rtmp-module
rm -r nginx-rtmp-module*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment