nginx添加ssl模块

发布时间 2023-03-25 23:59:27作者: zhenjingcool

背景:之前系统上线的时候不是https部署,现在需要https改造,需要把nginx添加ssl模块

既然之前安装的时候没有编译ssl模块,难道需要把nginx卸载重装?其实不需要,看下面步骤

1 到之前下载nginx包解压缩后的路径

[root@16s9 nginx-1.20.1]# pwd
/root/nginx-1.20.1
[root@16s9 nginx-1.20.1]#

之前nginx安装在了/root/nginx_new路径下面

执行命令(为了防止对当前运行的nginx_new路径有影响,我们配置prefix为nginx_new_with_ssl路径)

 [root@16s9 nginx-1.20.1]# ./configure --prefix=/root/nginx_new_with_ssl/ --with-http_ssl_module 

2 执行make命令

[root@16s9 nginx-1.20.1]# make
make -f objs/Makefile
make[1]: Entering directory `/root/nginx-1.20.1'

注意:为了尽量不影响之前的部署,我们这里不执行make install,不然一不小心会覆盖之前安装的nginx路径下的文件(虽然上面我们已经设置了新的prefix参数,但是小心点总是好的)。

执行make之后,将在objs路径下生成编译的nginx文件。

[root@16s9 objs]# ll
-rwxr-xr-x 1 root root 5970896 Mar 25 23:34 nginx
[root@16s9 objs]#

3 备份之前的nginx编译文件

[root@16s9 sbin]# pwd
/root/nginx_new/sbin
[root@16s9 sbin]# mv nginx nginx.bk

4 拷贝新编译的nginx文件到当前部署路径

[root@16s9 sbin]# pwd
/root/nginx_new/sbin
[root@16s9 sbin]# cp /root/nginx-1.20.1/objs/nginx ./
[root@16s9 sbin]# ll
total 9628
-rwxr-xr-x 1 root root 5970896 Mar 25 23:37 nginx
-rwxr-xr-x 1 root root 3883320 Nov  2  2021 nginx.bk
[root@16s9 sbin]#

5 查看是否安装成功

[root@16s9 sbin]# ./nginx -V
nginx version: nginx/1.20.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/root/nginx_new_with_ssl/ --with-http_ssl_module
[root@16s9 sbin]#

安装成功