Nginx 一键编译二进制编译升级/平滑升级脚本

132次阅读
没有评论

共计 3258 个字符,预计需要花费 9 分钟才能阅读完成。

Nginx 最新稳定版二进制编译升级脚本,实现一键升级.

    • 使用须知:

使用脚本前,确保机器已经安装了Nginx. 本脚本会添加一些常用且比较有用的模块. 脚本会从nginx.org直接下载最新的稳定版源码,进行编译. 已在Debian 8上通过测试. 除了安装依赖外,其余部分其他系统可照搬. 脚本运行完,自行重启Nginx即可.

  • 附加模块:
    • nchan
    • nginx-auth-pam
    • nginx-cache-purge
    • nginx-echo
    • nginx-lua
    • nginx-upstream-fair
    • ngx_http_substitutions_filter_module
  • 使用方法:
  • wget --no-check-certificate -qO- 'https://moeclub.org/attachment/LinuxShell/nginx_update.sh' |bash
    • 预览:
    • #!/bin/bash
      
      Debian_VER='jessie'
      Nginx_URL='http://nginx.org/packages/debian/pool/nginx/n/nginx/'
      
      Check_Status(){
        [ $? -eq '0' ] || exit 1
      }
      
      apt-get update
      apt-get install -f -y gcc make libexpat1 liblua5.1-0 libluajit-5.1-2 libluajit-5.1-common libluajit-5.1-dev libpam0g-dev zlib1g libxml2 libssl-dev libperl-dev libpcre3-dev libgd-dev libgoogle-perftools-dev p7zip-full
      Check_Status
      
      cd /tmp
      rm -rf ./nginx*
      
      Nginx_VER_TMP=$(wget --no-check-certificate -qO- "$Nginx_URL" |grep -o 'nginx_[^"]*' |grep -v '' |grep 'dsc$' |sort -nk 2 -t . |grep "$Debian_VER" |tail -n1)
      [ -n "$Nginx_VER_TMP" ] || Check_Status
      
      Nginx_VER_ORIG=$(echo "$Nginx_VER_TMP" |cut -d'-' -f1)
      [ -n "$Nginx_VER_ORIG" ] || Check_Status
      
      Nginx_VER_PATH=$(echo "$Nginx_VER_TMP" |cut -d'~' -f1)
      [ -n "$Nginx_VER_PATH" ] || Check_Status
      
      wget --no-check-certificate -qO 'nginx_modules.zip' 'https://moeclub.org/attachment/LinuxSoftware/nginx_modules.zip.deb'
      Check_Status
      
      wget --no-check-certificate -qO 'nginx.orig.tar.gz' "${Nginx_URL}${Nginx_VER_ORIG}.orig.tar.gz"
      Check_Status
      
      wget --no-check-certificate -qO "nginx.${Debian_VER}.tar.xz" "${Nginx_URL}${Nginx_VER_PATH}~${Debian_VER}.debian.tar.xz"
      Check_Status
      
      tar -xvf "nginx.orig.tar.gz"
      Check_Status
      cd ./nginx-*
      tar -xvf "../nginx.${Debian_VER}.tar.xz"
      Check_Status
      7z x "../nginx_modules.zip" -o./
      Check_Status
      
      ExtModule=''
      AddModules=' --add-module=./'
      for item in `find modules -maxdepth 1 -type d`
        do
          [ -n "$item" ] && [ -n "$(echo $item |grep '/')" ] && {
            AddModule="${AddModules}${item}"
            ExtModule="${ExtModule}${AddModule}"
          }
        done
      
      sed -i 's/^CFLAGS="$CFLAGS -g"$/#&/g' ./auto/cc/gcc
      Check_Status
      
      ./configure \
      --prefix=/usr/share/nginx \
      --conf-path=/etc/nginx/nginx.conf \
      --http-log-path=/var/log/nginx/access.log \
      --error-log-path=/var/log/nginx/error.log \
      --lock-path=/var/lock/nginx.lock \
      --pid-path=/run/nginx.pid \
      --modules-path=/usr/lib/nginx/modules \
      --http-client-body-temp-path=/var/lib/nginx/body \
      --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
      --http-proxy-temp-path=/var/lib/nginx/proxy \
      --http-scgi-temp-path=/var/lib/nginx/scgi \
      --http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
      --with-pcre-jit \
      --with-ipv6 \
      --with-threads \
      --with-http_addition_module \
      --with-http_auth_request_module \
      --with-http_flv_module \
      --with-http_gzip_static_module \
      --with-http_gunzip_module \
      --with-http_image_filter_module=dynamic \
      --with-http_mp4_module \
      --with-http_perl_module=dynamic \
      --with-http_realip_module \
      --with-http_secure_link_module \
      --with-http_slice_module \
      --with-http_ssl_module \
      --with-http_v2_module \
      --with-stream=dynamic \
      --with-stream_ssl_module \
      --with-google_perftools_module \
      --without-http_geo_module \
      --without-http_userid_module \
      --without-http_memcached_module \
      --without-http_split_clients_module \
      $(echo "$ExtModule")
      Check_Status
      
      make
      Check_Status
      
      Nginx_PATH="$(command -v nginx)"
      [ -n "$Nginx_PATH" ] || Check_Status
      [ -f "./objs/nginx" ] || Check_Status
      [ -f "$Nginx_PATH" ] && mv -f "${Nginx_PATH}" "${Nginx_PATH}.bak"
      cp -rf "./objs/nginx" "$Nginx_PATH"
      Check_Status
      
      mkdir -p /usr/local/share/man/man8
      cp -rf ./objs/nginx.8 /usr/local/share/man/man8/
      mandb
      
      rm -rf ./nginx*
      

       

正文完
 
admin
版权声明:本站原创文章,由 admin 2019-11-23发表,共计3258字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码