06 源码安装Nginx

# 安装依赖软件
[root@Nginx-LB conf.d]# yum install -y gcc glibc gcc-c++ pcre-devel openssl-devel patch
# 检查yum安装Nginx状态
[root@Nginx-LB conf.d]# nginx -v
nginx version: nginx/1.26.1
# 下载Nginx源码包
[root@Nginx-LB conf.d]# wget http://nginx.org/download/nginx-1.26.1.tar.gz
# 解压
[root@Nginx-LB opt]# tar -zxvf nginx-1.26.1.tar.gz
# 下载健康状态检查模块
[root@Nginx-LB opt]# wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zip
# 解压
[root@Nginx-LB opt]# unzip master.zip 
# 打补丁
[root@Nginx-LB opt]# cd nginx-1.26.1/             
[root@Nginx-LB nginx-1.26.1]# patch -p1 < ../nginx_upstream_check_module-master/check_1.20.1+.patch 
image-20241125195024638
图1 打补丁
# Nginx之前的默认模块
image-20241125195208683
图2 查看Yum安装的Nginx默认模块
# 把默认的复制下来
image-20241125195306567
图3 复制默认模块
# 重新配置Nginx
[root@Nginx-LB nginx-1.26.1]# ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=/opt/nginx_upstream_check_module-master

# 在最后面加的--add-module=/opt/nginx_upstream_check_module-master,是打补丁的安装包位置
# 编译安装
[root@Nginx-LB nginx-1.26.1]# make && make install
posted @ 2025-05-18 17:37  Chains_1  阅读(27)  评论(0)    收藏  举报