Skip to content

Instantly share code, notes, and snippets.

@vmlive
Last active April 14, 2018 06:48
Show Gist options
  • Save vmlive/9993932 to your computer and use it in GitHub Desktop.
Save vmlive/9993932 to your computer and use it in GitHub Desktop.
Nginx 一键安装脚本
#!/bin/bash
clear
echo "========================================================================="
echo "Nginx script V1.0 for CentOS/RadHat Linux Written by llama"
echo "========================================================================="
echo "A tool to auto-compile & install Nginx on Linux "
echo ""
echo "For more information please contact llama"
echo "========================================================================="
#
# # sample usage
# curl -o /tmp/install_nginx.sh https://gist.githubusercontent.com/vmlive/9993932/raw
# nohup /bin/bash /tmp/install_nginx.sh > /tmp/install_nginx.sh.log && rm -f /tmp/install_nginx.sh &
#
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
#add the third-party repo
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
#install packges
for packages in patch make cmake gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap libxslt-devel pcre pcre-devel gd-devel GeoIP-devel;
do yum -y install $packages; done
useradd nginx
groupadd nginx
cd /usr/local/src
if [ -s ngx_cache_purge-2.1.tar.gz ]; then
echo "ngx_cache_purge-2.1.tar.gz [found]"
else
echo "Error: ngx_cache_purge-2.1.tar.gz not found!!!download now......"
wget -c http://labs.frickle.com/files/ngx_cache_purge-2.1.tar.gz
fi
if [ -s nginx-1.4.7.tar.gz ]; then
echo "nginx-1.4.7.tar.gz [found]"
else
echo "Error: nginx-1.4.7.tar.gz not found!!!download now......"
wget -c http://nginx.org/download/nginx-1.4.7.tar.gz
fi
tar zxvf ngx_cache_purge-2.1.tar.gz
tar zxvf nginx-1.4.7.tar.gz
cd nginx-1.4.7
./configure --prefix=/etc/nginx \
--user=nginx \
--group=nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--http-log-path=/var/log/nginx/access.log \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-scgi-temp-path=/var/lib/nginx/scgi \
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
--lock-path=/var/lock/nginx.lock \
--pid-path=/var/run/nginx.pid \
--with-pcre-jit \
--with-debug \
--with-http_addition_module \
--with-http_dav_module \
--with-http_geoip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_sub_module \
--with-http_xslt_module \
--with-ipv6 \
--with-sha1=/usr/include/openssl \
--with-md5=/usr/include/openssl \
--with-mail \
--with-mail_ssl_module \
--add-module=/usr/local/src/ngx_cache_purge-2.1
make
make install
curl -o /etc/init.d/nginx https://gist.githubusercontent.com/vmlive/9994257/raw
chmod 755 /etc/init.d/nginx
# mkdir -p /etc/nginx/sites-available
# mkdir -p /etc/nginx/sites-enabled
mkdir -p /etc/nginx/conf.d
# rm -rf /etc/nginx/nginx.conf
# for cache
curl -o /etc/nginx/nginx.conf https://gist.githubusercontent.com/vmlive/10001382/raw
# for mirror
# curl -o /etc/nginx/nginx.conf https://gist.githubusercontent.com/vmlive/10022016/raw
mkdir -p /var/log/nginx
chown nginx:root /var/log/nginx
mkdir -p /var/lib/nginx
chown nginx:root /var/lib/nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment