• nginx添加https模块


    nginx添加https模块

    在配置文件nginx.conf,开启了https监听后,nginx -t检查报错如下,表明ssl参数需要使用ngx_http_ssl_module

    nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module
    

    检查现有模块

    查看nginx已安装的模块,说明没有http_ssl_module模块

    nginx -V
    ...
    configure arguments: --prefix=/usr/local/nginx --with-stream --without-http_gzip_module --without-http_rewrite_module
    

    开启http_ssl_module模块要加上--with_http_ssl_module,即configure arguments修改成

    --prefix=/usr/local/nginx --with-stream --without-http_gzip_module --without-http_rewrite_module --with-http_ssl_module
    

    nginx开启ssl模块

    进入到nginx源码目录下,进行

    cd /opt/nginx-1.20.0
    
    #进行编译前的检查
    ./configure --prefix=/usr/local/nginx --with-stream --without-http_gzip_module --without-http_rewrite_module --with-http_ssl_module
    

    由于没有安装openssl-devel组件,检查未通过,根据报错SSL modules require the OpenSSL library,知道了nginx的ssl模块需要openssl库,使用包管理工具安装.对于类似的报错情况,可根据错误提示自行处理

    ./configure: error: SSL modules require the OpenSSL library.
    You can either do not enable the modules, or install the OpenSSL library
    into the system, or build the OpenSSL library statically from the source
    with nginx by using --with-openssl=<path> option.
    
    yum install -y openssl-devel
    

    再次进行检查,直到echo $?返回状态码为0,表示通过检查,进行下一步

    ./configure --prefix=/usr/local/nginx --with-stream --without-http_gzip_module --without-http_rewrite_module --with-http_ssl_module
    
    echo $?
    0
    

    进行编译

    make
    

    这里不要进行make install,否则就是覆盖安装

    备份nginx可执行文件

    然后备份原有已安装好的nginx

    cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
    

    关闭nginx,替换可执行文件

    然后将刚刚编译好的nginx覆盖掉原有的nginx(这个时候nginx要停止状态)

    之前对nginx做了单元文件配置,可以通过系统命令控制nginx服务

    没有做单元配置的,直接使用原始命令操作即可

    两条命令执行一个就可以

    #关闭nginx
    systemctl stop nginxd.service
    #nginx原始命令
    nginx -s stop
    
    #强制覆盖nginx可执行文件
    \cp ./objs/nginx /usr/local/nginx/sbin/nginx
    

    检查nginx模块

    查看nginx模块参数,可以看到已经加载了--with-http_ssl_module参数

    nginx -V
    ...
    configure arguments: --prefix=/usr/local/nginx --with-stream --without-http_gzip_module --without-http_rewrite_module --with-http_ssl_module
    

    检查nginx配置

    nginx检查配置文件是否有错误,没有问题,就可以对外提供https服务

    nginx -t
    

    参考链接

    https://www.cnblogs.com/ghjbk/p/6744131.html

  • 相关阅读:
    Java面试题3
    Git 命令
    Flutter 基础控件
    Flutter工程目录
    GitHub简介
    Android Studio 安装 Flutter
    Android 权限管理
    结构型模式-适配器模式
    结构型模式-外观模式
    结构型模式-组合模式
  • 原文地址:https://www.cnblogs.com/anyux/p/15702007.html
Copyright © 2020-2023  润新知