rocky linux 源码编译nginx
侧边栏壁纸
  • 累计撰写 9 篇文章
  • 累计收到 1 条评论

rocky linux 源码编译nginx

photon
2025-08-06 / 1 评论 / 21 阅读 / 正在检测是否收录...

下载源码包并解压

新建目录,将下载的源码存放到该目录下(方便后续编译)

mkdir ${dir}
cd ${dir}

下载nginx源码

#下载nginx源码包
wget http://nginx.org/download/nginx-1.20.2.tar.gz
tar -zxvf nginx-1.26.3.tar.gz

安装相关依赖

sudo dnf install gcc-c++ gcc krb5 krb5-devel zlib zlib-devel pcre pcre-devel perl-devel perl-ExtUtils-Embed

设置nginx编译参数

创建build.sh脚本

vi build.sh

脚本内容如下

#!/bin/bash

CURRDIR=`dirname "$0"`
BASEDIR=`cd "$CURRDIR"; pwd`

VERSION=1.26.3
cd $BASEDIR/nginx-$VERSION

./configure --with-cc-opt='-fPIE' --with-ld-opt='-pie' --prefix=/usr/local/nginx/nginx-1.26.3 \
  --conf-path=/usr/local/nginx/nginx-1.26.3/conf/nginx.conf \
  --sbin-path=/usr/local/nginx/nginx-1.26.3/sbin/nginx \
  --pid-path=/usr/local/nginx/nginx-1.26.3/logs/nginx.pid \
  --error-log-path=/usr/local/nginx/nginx-1.26.3/logs/error.log \
  --http-log-path=/usr/local/nginx/nginx-1.26.3/logs/access.log \
  --http-client-body-temp-path=/usr/local/nginx/nginx-1.26.3/client_body_temp \
  --http-proxy-temp-path=/usr/local/nginx/nginx-1.26.3/proxy_temp \
  --http-fastcgi-temp-path=/usr/local/nginx/nginx-1.26.3/fastcgi_temp \
  --http-uwsgi-temp-path=/usr/local/nginx/nginx-1.26.3/uwsgi_temp \
  --http-scgi-temp-path=/usr/local/nginx/nginx-1.26.3/scgi_temp \
  --user=root \
  --group=root \
  --with-http_ssl_module \
  --with-http_realip_module \
  --with-http_flv_module \
  --with-http_mp4_module \
  --with-http_gunzip_module \
  --with-http_gzip_static_module \
  --with-http_secure_link_module \
  --with-http_v2_module \
  --with-http_stub_status_module \
  --with-http_sub_module \
  --with-http_perl_module \
  --with-mail \
  --with-mail_ssl_module \
  --with-stream \
  --with-stream_ssl_module \
  --with-file-aio \
  --with-ipv6 \
  --with-perl_modules_path=/usr/local/nginx/nginx-1.26.3/modules

make && make install
chmod +s /usr/local/nginx/nginx-1.26.3/sbin/nginx

执行构建

sudo sh build.sh

构建成功后,在/usr/local/nginx/nginx-1.26.3/sbin/nginx查看文件是否存在,并运行/usr/local/nginx/nginx-1.26.3/sbin/nginx -v 查看版本信息是否正确,以上nginx就构建完成了。

1

评论 (1)

取消
  1. 头像
    test
    iPhone · QQ Browser
    @

    测试评论

    回复