帮我写一个nginx最新版离线安装脚本,并编译常用模块
时间: 2024-04-05 21:31:16 浏览: 94
好的,以下是一个基于 CentOS 7 系统的 nginx 最新版离线安装脚本,并编译了一些常用模块:
```bash
#!/bin/bash
# Nginx version
NGINX_VERSION=1.21.3
# Download URL
NGINX_URL=http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
# Nginx modules
NGINX_MODULES=(
--with-http_ssl_module
--with-http_v2_module
--with-http_realip_module
--with-http_gzip_static_module
--with-http_stub_status_module
--with-stream
--with-stream_ssl_module
--with-stream_realip_module
--with-stream_ssl_preread_module
)
# PCRE library version
PCRE_VERSION=8.44
# Download URL
PCRE_URL=https://ftp.pcre.org/pub/pcre/pcre-${PCRE_VERSION}.tar.gz
# OpenSSL library version
OPENSSL_VERSION=1.1.1l
# Download URL
OPENSSL_URL=https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
# Download dependencies
yum -y install wget gcc make zlib-devel pcre-devel openssl-devel
# Download PCRE library
wget -O pcre-${PCRE_VERSION}.tar.gz ${PCRE_URL}
# Extract PCRE library
tar -xzvf pcre-${PCRE_VERSION}.tar.gz
# Download OpenSSL library
wget -O openssl-${OPENSSL_VERSION}.tar.gz ${OPENSSL_URL}
# Extract OpenSSL library
tar -xzvf openssl-${OPENSSL_VERSION}.tar.gz
# Download Nginx source code
wget -O nginx-${NGINX_VERSION}.tar.gz ${NGINX_URL}
# Extract Nginx source code
tar -xzvf nginx-${NGINX_VERSION}.tar.gz
# Configure and compile Nginx with modules
cd nginx-${NGINX_VERSION}
./configure \
--prefix=/usr/local/nginx \
--with-pcre=../pcre-${PCRE_VERSION} \
--with-openssl=../openssl-${OPENSSL_VERSION} \
${NGINX_MODULES[@]}
make
make install
# Create symbolic link
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
# Start Nginx
nginx
```
这个脚本会下载并编译最新版的 Nginx,同时编译了一些常用模块,例如 SSL、HTTP/2、Gzip 等。你可以通过修改 `NGINX_MODULES` 数组来添加或删除需要的模块。注意,这个脚本只在 CentOS 7 系统上进行测试过,如果你要在其他系统上运行,请自行进行适当修改。
阅读全文