麒麟服务器nginx支持ssl_preread

返回
Author Avatar
钢翼
2025-11-24
编程
17

麒麟系统上通过yum install安装的nginx不支持stream的ssl_preread。导致内网的应用需要调用互联网不同服务的接口(都是443端口)时,想直接通过跳板机的nginx处理就很难区分不同的服务。
这个时候我们需要自己编译nginx。

# 0.安装依赖
yum install -y gcc gcc-c++ make wget openssl-devel pcre-devel pcre zlib-devel perl-devel perl-ExtUtils-Embed
# 1.下载nginx
wget https://nginx.org/download/nginx-1.24.0.tar.gz
# 2.解压
tar -zxvf nginx-1.24.0.tar.gz
# 3.进入目录
cd /root/nginx-1.24.0
# 4.配置命令
./configure --prefix=/usr/share/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=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-http_ssl_module --with-pcre --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module
# 5.编译(-j后接CPU核心数,加快编译速度,如-j4)
make -j4
# 6.安装
make install

设置麒麟系统自启动服务

vi /usr/lib/systemd/system/nginx.service

写入以下内容

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

启动并配置服务生效

# 重新加载systemctl
systemctl daemon-reload
systemctl start nginx
systemctl enable nginx