From 8693b985a42449bfb45544181326d6c95600f3e2 Mon Sep 17 00:00:00 2001 From: bohung Date: Thu, 4 Aug 2022 12:22:40 +0800 Subject: [PATCH] Upload install nginx script. --- install_nginx.sh | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 install_nginx.sh diff --git a/install_nginx.sh b/install_nginx.sh new file mode 100644 index 0000000..fd26594 --- /dev/null +++ b/install_nginx.sh @@ -0,0 +1,71 @@ +#!/bin/bash +ubuntu_ver="$(lsb_release -rs)" +sudo echo "Starting " +org_pwd="$(pwd)" +cpu_cores="$(nproc --all)" +openssl_ver="$(openssl version|xargs| awk '{print $2}')" +openssl_dir="" +openssl_source_dir="" +if [[ "$openssl_ver" < "1.1.1" ]]; then + # Build openssl + target_openssl_ver="1.1.1m" + sudo bash -l -c " + cd /root && + wget https://www.openssl.org/source/openssl-$target_openssl_ver.tar.gz --no-check-certificate && + tar xzvf openssl-$target_openssl_ver.tar.gz && + cd openssl-$target_openssl_ver && + ./config no-ssl2 no-ssl3 zlib-dynamic -fPIC shared --prefix=/opt/openssl && + make depend -j$cpu_cores && make install && + rm -f /usr/bin/openssl && + ln -s /opt/openssl/bin/* /usr/bin/. && + echo'/opt/openssl/lib' > /etc/ld.so.conf.d/openssl.conf && + ldconfig" + openssl_ver="$target_openssl_ver" + cd "$org_pwd" + openssl_dir="/opt/openssl" + openssl_source_dir="/root/openssl-$target_openssl_ver" +fi +if [ -z "$cpu_cores" ]; then + cpu_cores="1"; +fi +if [[ "$ubuntu_ver" < "16" ]]; then #Need update ca-certificates manual + sudo bash -l -c " + cd /root && + wget https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/ca-certificates/20210119~20.04.2/ca-certificates_20210119~20.04.2.tar.xz --no-check-certificate && + tar -xJf ca-certificates_20210119~20.04.2.tar.xz && + cd ca-certificates-20210119~20.04.1 && + make -j$cpu_cores && make install && + dpkg-reconfigure -fnoninteractive ca-certificates && + update-ca-certificates --fresh --verbose && + /usr/bin/c_rehash /etc/ssl/certs" + cd "$org_pwd" +else + sudo apt-get update + sudo apt-get install --reinstall ca-certificates -y +fi +nginx_configure="" +if [ -z $openssl_source_dir ]; then + nginx_configure="./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-debug --with-compat --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module" +else + nginx_configure="./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-debug --with-compat --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module --with-openssl=$openssl_source_dir" +fi +nginx_ver="$(nginx -v 2>&1|xargs|awk '{print $3}'|cut -d '/' -f 2)" + +nginx_target_ver="1.23.1" +if [[ "$nginx_ver" < $nginx_target_ver ]]; then + #Build nginx and install + sudo bash -l -c " + cd /root && + wget http://nginx.org/download/nginx-$nginx_target_ver.tar.gz && + tar -zxvf nginx-$nginx_target_ver.tar.gz && + cd nginx-$nginx_target_ver && + apt remove nginx --purge -y && + apt-get -y install libpcre3 libpcre3-dev libxml2 libxml2-dev libxslt-dev libgd-dev && + $nginx_configure && + make -j$cpu_cores && make install && + rm -f /usr/sbin/nginx && + ln -s /usr/share/nginx/sbin/nginx /usr/sbin/. && + service nginx restart + " + cd "$org_pwd" +fi \ No newline at end of file