基于 OpenSSL 源码为 nginx 配置并安装 http_ssl_module

本文指导如何基于OpenSSL源码为nginx配置并安装http_ssl_module。首先,从nginx官网下载并解压,然后了解配置,创建安装目录。接着,配置http_ssl_module,下载openssl-3.0.5源码。通过make和make install完成安装,最后启动nginx并验证https的有效性。

基于 OpenSSL 源码为 nginx 配置并安装 http_ssl_module

下载并解压

https://nginx.org/en/download.html

wget https://nginx.org/download/nginx-1.22.0.tar.gz

tar -xzvf nginx-1.22.0.tar.gz

mv nginx-1.22.0 nginx

配置以及准备

https://nginx.org/en/docs/

https://nginx.org/en/docs/configure.html

认识配置

cd nginx
configure --help

  --help                             print this message

  --prefix=PATH                      set installation prefix
  --sbin-path=PATH                   set nginx binary pathname
  --modules-path=PATH                set modules path
  --conf-path=PATH                   set nginx.conf pathname
  --error-log-path=PATH              set error log pathname
  --pid-path=PATH                    set nginx.pid pathname
  --lock-path=PATH                   set nginx.lock pathname

  --user=USER                        set non-privileged user for
                                     worker processes
  --group=GROUP                      set non-privileged group for
                                     worker processes

  --build=NAME                       set build name
  --builddir=DIR                     set build directory

  --with-select_module               enable select module
  --without-select_module            disable select module
  --with-poll_module                 enable poll module
  --without-poll_module              disable poll module

  --with-threads                     enable thread pool support

  --with-file-aio                    enable file AIO support

  --with-http_ssl_module             enable ngx_http_ssl_module
  --with-http_v2_module              enable ngx_http_v2_module
  --with-http_realip_module          enable ngx_http_realip_module
  --with-http_addition_module        enable ngx_http_addition_module
  --with-http_xslt_module            enable ngx_http_xslt_module
  --with-http_xslt_module=dynamic    enable dynamic ngx_http_xslt_module
  --with-http_image_filter_module    enable ngx_http_image_filter_module
  --with-http_image_filter_module=dynamic
                                     enable dynamic ngx_http_image_filter_module
  --with-http_geoip_module           enable ngx_http_geoip_module
  --with-http_geoip_module=dynamic   enable dynamic ngx_http_geoip_module
  --with-http_sub_module             enable ngx_http_sub_module
  --with-http_dav_module             enable ngx_http_dav_module
  --with-http_flv_module             enable ngx_http_flv_module
  --with-http_mp4_module             enable ngx_http_mp4_module
  --with-http_gunzip_module          enable ngx_http_gunzip_module
  --with-http_gzip_static_module     enable ngx_http_gzip_static_module
  --with-http_auth_request_module    enable ngx_http_auth_request_module
  --with-http_random_index_module    enable ngx_http_random_index_module
  --with-http_secure_link_module     enable ngx_http_secure_link_module
  --with-http_degradation_module     enable ngx_http_degradation_module
  --with-http_slice_module           enable ngx_http_slice_module
  --with-http_stub_status_module     enable ngx_http_stub_status_module

  --without-http_charset_module      disable ngx_http_charset_module
  --without-http_gzip_module         disable ngx_http_gzip_mod
### 如何在 Nginx 1.18.0 中编译或加载 ngx_http_ssl_module 模块 要在 Nginx 1.18.0 中启用 `ngx_http_ssl_module` 模块,通常需要通过重新编译 Nginx 来完成。以下是具体方法: #### 准备工作 首先,确保已安装必要的依赖项。对于 CentOS 和 Ubuntu 系统,可以分别运行以下命令来安装所需的工具和: ```bash # 对于CentOS yum groupinstall "Development Tools" yum install pcre-devel zlib-devel openssl-devel # 对于Ubuntu apt-get update apt-get install build-essential libpcre3-dev zlib1g-dev libssl-dev ``` #### 下载解压 Nginx 源码 下载指定版本的 Nginx 解压缩文件: ```bash wget http://nginx.org/download/nginx-1.18.0.tar.gz tar -zxvf nginx-1.18.0.tar.gz cd nginx-1.18.0 ``` #### 配置编译选项 为了启用 SSL 支持,在执行 `./configure` 命令时需加入 `--with-http_ssl_module` 参数。如果已经存在其他模块,则将其保留与该参数一起传递。 例如,仅启用基本功能加上 HTTPS 的情况下可使用如下配置命令[^1]: ```bash ./configure --prefix=/usr/local/nginx \ --with-http_ssl_module ``` 当需要额外的功能比如 IPv6 或者第三方模块如 `ngx_http_proxy_connect_module` 时,可以根据需求调整上述命令中的选项。例如同时支持 HTTP/HTTPS 正向代理以及 IPv6 地址访问的情况下的完整配置可能是这样的[^2][^3]: ```bash ./configure --prefix=/usr/local/nginx \ --with-http_ssl_module \ --with-stream \ --with-mail \ --with-mail_ssl_module \ --add-module=/path/to/your/custom/modules \ --with-ipv6 ``` > **注意**: `/path/to/your/custom/modules` 应替换为你实际存放自定义模块的位置路径。 #### 编译与安装 一旦成功完成了 configure 脚本的操作之后就可以继续进行编译过程了。 ```bash make && make install ``` 至此,新的带有 ssl 功能的支持版 Nginx 就已经被构建出来了,位于默认目录下 (`/usr/local/nginx`) 。启动服务前记得停止旧的服务实例以免端口占用冲突等问题发生。 --- ### 注意事项 - 如果当前正在运行的是由包管理器(APT/YUM)安装的标准二进制发行版 NGINX ,那么可能无法直接应用这些更改;此时建议备份现有环境后再按照以上步骤操作或者考虑升级至源码分发形式维护更灵活的方式上来满足特定业务场景的需求。 - 在生产环境中实施任何变更之前,请务必先在一个隔离测试环境下验证新版本的行为表现正常无误后才推广上线! ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值