ubuntu和centos编译安装nginx脚本
#!/bin/bash
NG_VERSION=nginx-1.24.0
INSTALL_DIR=/usr/local/nginx
# 判断系统类型
if [ -f /etc/lsb-release ]; then
    # Ubuntu
    echo "Detected Ubuntu"
    apt update && apt install wget make gcc libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev build-essential libgd-dev -y
elif [ -f /etc/redhat-release ]; then
    # CentOS
    echo "Detected CentOS"
    sudo yum install wget gcc pcre pcre-devel openssl-devel openssl gzip createrepo make cmake zlib-devel tar lrzsz gd-devel -y
else
    echo "Unsupported system"
    exit 1
fi
useradd -s /sbin/nologin nginx -m
wget http://nginx.org/download/$NG_VERSION.tar.gz
tar -xf $NG_VERSION.tar.gz
cd $NG_VERSION
./configure --prefix=/usr/local/nginx \
--with-pcre \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_image_filter_module \
--with-http_slice_module \
--with-threads \
--with-file-aio \
--with-stream \
--with-stream_ssl_module
make
make install

cat > /lib/systemd/system/nginx.service <<EOF
    [Unit]
Description=nginx service
After=network.target
   
[Service]
Type=forking 
ExecStart=$INSTALL_DIR/sbin/nginx
ExecReload=$INSTALL_DIR/sbin/nginx -s reload
ExecStop=$INSTALL_DIR/sbin/nginx -s quit
PrivateTmp=true 
   
[Install] 
WantedBy=multi-user.target
EOF
systemctl daemon-reload 
systemctl enable nginx --now


本文 暂无 评论

Top