Skip to content

Instantly share code, notes, and snippets.

@SalimF
Last active May 5, 2018 15:58
Show Gist options
  • Save SalimF/e0971956a391b75ed5aed6d91f61799b to your computer and use it in GitHub Desktop.
Save SalimF/e0971956a391b75ed5aed6d91f61799b to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# سكربت تتبيث انتجين اكس مع موديل البث rtmp
# https://bit.ly/2jxTUHv
# install Nginx with rtmp support
# make script exit if a simple command fails and
# make script print commands being executed
set -e -x
# Build path
export BUILD_PATH=/usr/local
export BPATH=$BUILD_PATH/nginx-build
# names of latest versions of each package
export VERSION_PCRE=pcre-8.38
export VERSION_OPENSSL=openssl-1.0.2f
export VERSION_NGINX=nginx-1.14.0
# URLs to the source directories
export SOURCE_OPENSSL=https://www.openssl.org/source/
export SOURCE_PCRE=https://netix.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz
export SOURCE_NGINX=http://nginx.org/download/
export SOURCE_RTMP=https://github.com/arut/nginx-rtmp-module.git
# make a 'today' variable for use in back-up filenames later
today=$(date +"%Y-%m-%d")
# clean out any files from previous runs of this script
cd $BUILD_PATH
rm -rf /etc/nginx
rm -rf nginx-build
rm -rf /var/cache/nginx
mkdir /var/cache/nginx
mkdir nginx-build
cd nginx-build
# ensure that we have the required software to compile our own nginx
apt-get update && apt-get -y install \
build-essential \
curl \
libssl-dev \
libxslt1-dev
# grab the source files
wget $SOURCE_PCRE
wget $SOURCE_OPENSSL$VERSION_OPENSSL.tar.gz
wget $SOURCE_NGINX$VERSION_NGINX.tar.gz
# expand the source files
tar xzf $VERSION_PCRE.tar.gz
tar xzf $VERSION_OPENSSL.tar.gz
tar xzf $VERSION_NGINX.tar.gz
# clone nginx rtmp module
git clone $SOURCE_RTMP
# set where OpenSSL and nginx will be built
export STATICLIBSSL="$BPATH/staticlibssl"
# build static openssl
cd $BPATH/$VERSION_OPENSSL
rm -rf "$STATICLIBSSL"
mkdir "$STATICLIBSSL"
make clean
./config --prefix=$STATICLIBSSL no-shared no-ssl2 no-ssl3 no-idea \
&& make depend \
&& make -j4 \
&& make install_sw
# build nginx, with various modules included/excluded
cd $BPATH/$VERSION_NGINX
./configure --with-cc-opt="-I $STATICLIBSSL/include -I/usr/include" \
--with-ld-opt="-L $STATICLIBSSL/lib -Wl,-rpath -lssl -lcrypto -ldl -lz" \
--with-pcre=$BPATH/$VERSION_PCRE \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/conf/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 \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_sub_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-file-aio \
--without-mail_imap_module \
--without-mail_pop3_module \
--without-mail_smtp_module \
--with-http_v2_module \
--with-ipv6 \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-http_slice_module \
--add-module=$BPATH/nginx-rtmp-module \
&& make -j4 && make install
# Move the build to /etc/nginx
mv $BPATH/$VERSION_NGINX /etc/nginx
cp $BPATH/nginx-rtmp-module/stat.xsl /usr/local/nginx/html
echo "All done.";
echo "This build has not edited your existing /etc/nginx directory.";
echo "WWW folder = /usr/local/nginx/html";
echo "To restart the nginx service : sudo service nginx restart";
nginx -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment