目录
目录X
银河麒麟系统openssl-devel组件缺失环境 Nginx 离线编译安装步骤(自定义 OpenSSL 目录)
1, 准备工作
下载 Nginx 源码:
cd ~ wget http://nginx.org/download/nginx-1.28.1.tar.gz tar xf nginx-1.28.1.tar.gz
下载 OpenSSL 源码:
cd ~ wget https://www.openssl.org/source/openssl-1.1.1f.tar.gz tar xf openssl-1.1.1f.tar.gz
假设解压目录:
/root/nginx-1.28.1 /root/openssl-1.1.1f
确保系统已安装依赖工具(gcc、make、pcre2、zlib)
gcc --version make --version rpm -q pcre2 zlib zlib-devel
2, 编译 OpenSSL(为 Nginx 静态链接使用)
进入 OpenSSL 源码目录:
cd /root/openssl-1.1.1f
编译并安装到临时目录:
# 配置为静态编译,不安装共享库 ./config no-shared no-threads --prefix=/root/openssl-install make -j$(nproc) make install_sw
完成后,目录结构示例:
/data/xxx/openssl-install/include/openssl/*.h /data/xxx/openssl-install/lib/libssl.a /data/xxx/openssl-install/lib/libcrypto.a
3,编译 Nginx(指定 OpenSSL 源码目录)
进入 Nginx 源码目录:
cd /root/nginx-1.28.1
运行 configure:
./configure \ --prefix=/etc/nginx \ --with-http_ssl_module \ --with-http_v2_module \ --with-pcre \ --with-zlib=/usr \ --with-openssl=/root/openssl-1.1.1f
--with-openssl=<路径>:指定自定义 OpenSSL 源码目录--with-http_ssl_module:启用 SSL 模块--with-http_v2_module:启用 HTTP/2 模块
4, 编译
make -j$(nproc) make install
make install会把 Nginx 安装到你指定的 prefixSSL 模块静态链接了自定义 OpenSSL,不依赖系统库
5, 创建运行用户(可选)
# 只创建 nginx 用户,不创建组 useradd -r -s /sbin/nologin nginx
确保日志目录可写:
chown -R nginx:nginx /etc/nginx/logs
6, 测试配置
/etc/nginx/sbin/nginx -t
成功输出:
nginx: configuration file /etc/nginx/conf/nginx.conf syntax is ok
7, 启动 Nginx
/etc/nginx/sbin/nginx
查看进程:
ps -ef | grep nginx
测试 HTTPS:
curl -vk https://127.0.0.1
8, 清理临时目录(可选)
编译完成后,可以删除 OpenSSL 源码和临时安装目录:
rm -rf /root/openssl-1.1.1f rm -rf /root/openssl-install
因为 OpenSSL 已经被静态编译到 Nginx,运行不再依赖源码
✅ 小结
核心思路:用 Nginx 自带
--with-openssl指定源码目录,静态编译 SSL,绕过系统依赖优点:
离线环境可行
不破坏系统现有 OpenSSL
可控制 OpenSSL 版本
注意事项:
如果要使用国密算法,需要使用定制 OpenSSL
日志和工作目录必须可写,否则启动失败