侧边栏壁纸
博主头像
cn2linux博主等级

行动起来,活在当下

  • 累计撰写 127 篇文章
  • 累计创建 1 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

服务部署 编译Nginx

设置环境变量

export USER=www
export NGINX_VERSION=1.25.3
export SSL_VERSION=1.1.1w
export CPUS=$(grep 'cores' /proc/cpuinfo |wc -l)

创建服务账号

id ${USER}||useradd ${USER}  -M -s /usr/bin/false

安装依赖

dnf install -y pcre pcre-devel openssl-devel gcc zlib-devel mlocate gd gd-devel geoip-devel -y

下载相关源码包并解压

curl -L https://www.openssl.org/source/openssl-${SSL_VERSION}.tar.gz | \
tar xz -C /opt
git clone https://github.com/openresty/echo-nginx-module.git \
/opt/echo-nginx-module
git clone https://github.com/vision5/ngx_devel_kit.git \
/opt/ngx_devel_kit
git clone https://github.com/openresty/set-misc-nginx-module.git \
/opt/set-misc-nginx-module
curl -L http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz | \
tar xz -C /opt
curl -L https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz |\
tar xz 
cd nginx-${NGINX_VERSION}

相关扩展包说明

  1. OpenSSL:提供安全套接字层(SSL)和传输层安全(TLS)协议的开源工具包。

  2. echo-nginx-module:实现在 Nginx 服务器上处理高级 HTTP 请求和响应的模块。

  3. ngx_devel_kit:用于开发 Nginx 模块的工具包。

  4. set-misc-nginx-module:提供额外的 Nginx 指令,用于处理请求和响应。

  5. ngx_cache_purge:清除 Nginx 服务器缓存内容的模块。

编译NGINX

./configure --prefix=/usr/local/nginx-${NGINX_VERSION} \
--user=www --group=www  \
--with-threads \
--with-poll_module \
--with-pcre-jit \
--with-http_ssl_module  \
--with-http_v2_module   \
--with-http_v3_module  \
--with-http_realip_module \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--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_auth_request_module \
--with-http_stub_status_module  \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--add-module=/opt/echo-nginx-module \
--add-module=/opt/ngx_devel_kit \
--add-module=/opt/set-misc-nginx-module \
--add-module=/opt/ngx_cache_purge-2.3/ \
--with-openssl=/opt/openssl-${SSL_VERSION}/
make -j${CPUS} && make install

动态加载说明及引用方式

  • 使用 --with-http_image_filter_module=dynamic 选项时,模块被编译为动态模块(.so 文件),可以在 Nginx 运行时动态加载。

  • 这提供了更大的灵活性,因为您可以在不重新编译 Nginx 的情况下添加或移除该模块。这对于模块的更新和维护特别有用。

  • 动态模块 (--with-http_image_filter_module=dynamic):提供更高的灵活性和易维护性,但需要额外的配置步骤来加载。

load_module modules/ngx_http_image_filter_module.so;

events {
    # ... 事件配置 ...
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    
    # ... 其他 http 配置 ...
}

添加软连接

 ln -s /usr/local/nginx-1.25.3/ /usr/local/nginx

添加NGINX环境变量

cat > /etc/profile.d/NGINX-BIN.sh <<EOF
export NGINX_BIN=/usr/local/nginx/sbin/
export PATH=\${PATH}:\${NGINX_BIN}
EOF

source /etc/profile.d/NGINX-BIN.sh

清除环境变量

unset USER PHP_VERSION CPUS

0
  • ${post.likes!0}

评论区