本文章给运维从业人员提供了一套完整的、经过实战验证的Nginx正向代理部署解决方案,涵盖了RHEL9系统下的编译安装、详细配置、性能优化及安全加固等全流程。帮助运维人员快速搭建高效稳定的正向代理服务,满足企业内网访问互联网的安全需求。
一、先决条件
- 操作系统:Red Hat Enterprise Linux release 9.7 (Plow)
- nginx版本:1.28.0
二、安装步骤
(一)安装编译环境
[root@shizhanxia.com nginx-1.28.0]# yum -y install gcc wget automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel make
(二)编译安装
1.下载Nginx
[root@shizhanxia.com ~]# wget http://nginx.org/download/nginx-1.28.0.tar.gz
2.然后就是将下载下来的Nginx解压缩。
[root@shizhanxia.com ~]# tar zxvf nginx-1.28.0.tar.gz
3.进入解压缩后的Nginx目录。如果你要定制版本号可以更改源码目录src/core/nginx.h文件。
[root@shizhanxia.com ~]# cd nginx-1.28.0/
4.创建一个nginx目录用来存放运行的临时文件夹。
[root@shizhanxia.com nginx-1.28.0]# mkdir -p /etc/nginx [root@shizhanxia.com nginx-1.28.0]# mkdir -p /var/cache/nginx [root@shizhanxia.com nginx-1.28.0]# useradd app01
5.下载并将ngx_http_proxy模块添加到源代码
安装git
[root@shizhanxia.com nginx-1.28.0]# yum install git -y
下载ngx_http_proxy模块
[root@shizhanxia.com nginx-1.28.0]# git clone https://github.com/chobits/ngx_http_proxy_connect_module
提示:如果无法访问github,可以从本文末尾附件下载。
安装patch
[root@shizhanxia.com nginx-1.28.0]# yum install -y patch
添加patch补丁到源代码
[root@shizhanxia.com nginx-1.28.0]# patch -p1 < ./ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_102101.patch
6.编译Nginx
【配置】检查系统环境并生成构建文件
[root@shizhanxia.com nginx-1.28.0]# ./configure \ --prefix=/etc/nginx \ --sbin-path=/usr/sbin/nginx \ --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=app01 \ --group=app01 \ --with-pcre \ --with-http_v2_module \ --with-http_ssl_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-mail \ --with-mail_ssl_module \ --with-file-aio \ --with-ipv6 \ --with-http_v2_module \ --with-threads \ --with-stream \ --with-stream_ssl_module \ --add-module=./ngx_http_proxy_connect_module
【编译】根据Makefile编译源代码
[root@shizhanxia.com nginx-1.28.0]# make
【安装】将编译好的文件安装到系统目录
[root@shizhanxia.com nginx-1.28.0]# make install
剩余内容需解锁后查看
原创文章,作者:实战侠-保哥,如若转载,请注明出处:https://www.shizhanxia.com/solutions/nginx-compile-install-configure-on-rhel8-rhel9-guide-html.html
微信扫一扫
支付宝扫一扫
