Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Nginx 一键安装脚本
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/
# nohup /bin/bash /tmp/ > /tmp/ && rm -f /tmp/ &
# 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
#add the third-party repo
rpm -Uvh
#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]"
echo "Error: ngx_cache_purge-2.1.tar.gz not found!!!download now......"
wget -c
if [ -s nginx-1.4.7.tar.gz ]; then
echo "nginx-1.4.7.tar.gz [found]"
echo "Error: nginx-1.4.7.tar.gz not found!!!download now......"
wget -c
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/ \
--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 \
make install
curl -o /etc/init.d/nginx
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
# for mirror
# curl -o /etc/nginx/nginx.conf
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