Last active
January 7, 2020 04:02
-
-
Save nikkomiu/cd15d615fc3390ebbd79e9d078458d10 to your computer and use it in GitHub Desktop.
NGINX Custom Installation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: | |
## curl https://gist.githubusercontent.com/nikkomiu/cd15d615fc3390ebbd79e9d078458d10/raw/nginx_install.sh | bash -s 1.12.0 | |
# Set up variables | |
PCRE_VERSION="8.40" | |
ZLIB_VERSION="1.2.11" | |
OPENSSL_VERSION="1.0.2f" | |
UPSTREAM_CHECK_VERSION="0.3.0" | |
# Ensure run as root | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
exit 1 | |
fi | |
if command -v yum; then | |
yum groupinstall -y 'Development Tools' | |
elif command -v apt-get; then | |
apt-get update | |
apt-get install -y build-essential | |
elif command -v apk; then | |
apk add --no-cache \ | |
gcc libc-dev \ | |
make openssl-dev \ | |
pcre-dev zlib-dev \ | |
linux-headers libxslt-dev \ | |
gd-dev geoip-dev \ | |
perl-dev libedit-dev \ | |
mercurial bash \ | |
alpine-sdk findutils | |
else | |
echo "Could not determine package manager!" | |
exit 1 | |
fi | |
START_DIR=`pwd` | |
cd /opt/ | |
# == Install PCRE Library | |
if [ ! -d "/opt/pcre-$PCRE_VERSION" ]; then | |
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-$PCRE_VERSION.tar.gz | |
tar -zxf pcre-$PCRE_VERSION.tar.gz | |
cd pcre-$PCRE_VERSION | |
./configure | |
make | |
make install | |
cd .. | |
rm -rf pcre-$PCRE_VERSION.tar.gz | |
else | |
echo "Skipping PCRE Setup" | |
fi | |
# == End Install PCRE Library | |
# == Install ZLIB Library | |
if [ ! -d "/opt/zlib-$ZLIB_VERSION" ]; then | |
wget http://zlib.net/zlib-$ZLIB_VERSION.tar.gz | |
tar -zxf zlib-$ZLIB_VERSION.tar.gz | |
cd zlib-$ZLIB_VERSION | |
./configure | |
make | |
make install | |
cd .. | |
rm -rf zlib-$ZLIB_VERSION.tar.gz | |
else | |
echo "Skipping ZLIB Setup" | |
fi | |
# == End Install ZLIB Library | |
# == Install OpenSSL Library | |
if [ ! -d "/opt/openssl-$OPENSSL_VERSION" ]; then | |
wget http://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz | |
tar -zxf openssl-$OPENSSL_VERSION.tar.gz | |
cd openssl-$OPENSSL_VERSION | |
./configure darwin64-x86_64-cc --prefix=/usr | |
make | |
make install | |
cd .. | |
rm -rf openssl-$OPENSSL_VERSION.tar.gz | |
else | |
echo "Skipping OpenSSL Setup" | |
fi | |
# == End Install OpenSSL Library | |
# == Fetch Upstream Check | |
if [ ! -d "/opt/upstream_check_module-0.3.0" ]; then | |
wget -O upstream_check.tar.gz https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz | |
tar -zxf upstream_check.tar.gz | |
rm -rf upstream_check.tar.gz | |
else | |
echo "Skipping upstream_check Fetch" | |
fi | |
# == End Fetch Upstream Check | |
cd /tmp | |
eval "wget http://nginx.org/download/nginx-$1.tar.gz" | |
eval "tar -xvf nginx-$1.tar.gz" | |
eval "cd nginx-$1" | |
# Change server header value | |
sed -i -e 's/Server: " NGINX_VER_BUILD/Server: awesome-apricot"/g' ./src/http/ngx_http_header_filter_module.c | |
sed -i -e 's/Server: " NGINX_VER/Server: awesome-apricot"/g' ./src/http/ngx_http_header_filter_module.c | |
sed -i -e 's/Server: nginx/Server: awesome-apricot/g' ./src/http/ngx_http_header_filter_module.c | |
./configure \ | |
--sbin-path=/usr/bin/nginx \ | |
--conf-path=/etc/nginx/nginx.conf \ | |
--pid-path=/var/run/nginx.pid \ | |
--error-log-path=/var/log/nginx/error.log \ | |
--http-log-path=/var/log/nginx/access.log \ | |
--with-http_ssl_module \ | |
--with-http_v2_module \ | |
--with-file-aio \ | |
--with-ipv6 \ | |
--with-stream \ | |
--with-http_slice_module \ | |
--with-threads \ | |
--with-http_gzip_static_module \ | |
--with-http_stub_status_module \ | |
--with-pcre=/opt/pcre-8.40 \ | |
--with-zlib=/opt/zlib-1.2.11 \ | |
--with-openssl=/opt/openssl-1.0.2f \ | |
--add-module=/opt/nginx_upstream_check_module-0.3.0 \ | |
--without-mail_pop3_module \ | |
--without-mail_smtp_module \ | |
--without-mail_imap_module | |
make | |
make install | |
chmod +x /usr/bin/nginx | |
cd .. | |
eval "rm -rf nginx-$1*" | |
cd $START_DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment