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

上一篇:Maven之no dependency information available解决


下一篇:SpringBoot服务间使用自签名证书实现https双向认证