Nginx配置Https缺少SSL模块

1、Linux下Nginx配置https

  • nginx下载和安装此处就忽略,可自行百度

1.1、配置https

打开nginx配置文件

shell 复制代码
vim /opt/app/nginx/conf/nginx.conf

相关https配置

shell 复制代码
server {
    listen 443 ssl; #开放端口
    server_name echarts.net;#域名
    #redirect to https
    #ssl on; #旧版
 
    #ssl证书地址
    ssl_certificate    /opt/app/nginx/conf/cert/*****.pem; #pem
    ssl_certificate_key /opt/app/nginx/conf/cert/****.key; #key
 
 
     location / {
     	# 代理请求的地址和开放端口
        proxy_pass  http://localhost:8099;
        #proxy_set_header X-Forwarded-Proto  $scheme;
        #add_header Content-Security-Policy upgrade-insecure-requests;
     }
}

键盘按下ESC键,输入:wq 表示保存退出

其他部分解释:!强制退出、q 退出

测试配置文件是否正确

在nginx目录下输入一下命令

shell 复制代码
./sbin/nginx -tc conf/nginx/conf

出现以下示例表示配置成功

如果出现以下示例字样表示缺少ngx_http_ssl_module模块

the "ssl" parameter requires ngx_http_ssl_module

证明此时Nginx缺少该模块
此时要将刚才的关于https的配置用#先全部注释掉,否则后期停服会报配置文件错误

1.2、下载并配置https

  1. 找到Nginx安装目录

比如我的在/opt/software/nginx-1.22.1

typescript 复制代码
cd /opt/software/nginx-1.22.1

如果实在找不到,那就查看Nginx版本号重新下载一个

查看Nginx版本号 (/usr/local/nginx/是你Nginx服务器的实际位置)

typescript 复制代码
/opt/app/nginx/sbin/nginx -V

查看configure arguments:后边有没有值,如果有,就复制下来。

  1. 从新配置SSL模块

进入nginx源码包目录,运行:

shell 复制代码
./configure --prefix=/opt/app/nginx --with-http_stub_status_module --with-http_ssl_module --原来有的模块(如果有的话)

如果运行之后,最终报错如下:

2.1 下载OpenSSL库(没报错可忽略该步骤)

shell 复制代码
yum -y install openssl openssl-devel

配置完成后,运行命令make命令

make

注意,此处不能mark install 否则就是覆盖安装

3、 替换已安装好的Nginx包

替换之前先备份:

shell 复制代码
cp /opt/app/nginx/sbin/nginx /opt/app/nginx/sbin/nginx.bak

先停止Nginx服务

停止服务

shell 复制代码
./opt/app/nginx/sbin/nginx -s stop

将刚刚编译好的nginx覆盖掉原有的nginx

在Nginx解压目录下使用以下命令

shell 复制代码
cp ./objs/nginx /opt/app/nginx/sbin/

通过查看版本命令收看是否下载SSL模块成功

/opt/app/nginx/sbin/nginx -V

此时应该显示为即配置成功:

shell 复制代码
configure arguments: --prefix=/opt/app/nginx --with-http_stub_status_module --with-http_ssl_module

启动服务即可,命令如下

shell 复制代码
/opt/app/nginx/sbin/nginx
相关推荐
小池先生10 小时前
服务请求出现偶发超时问题,经查服务本身没问题,问题出现在nginx转发。
运维·服务器·nginx
卓码软件测评16 小时前
第三方媒体流压力测试:k6插件xk6-webrtc的使用来测试媒体流的性能
网络协议·测试工具·http·https·webrtc·ssl·媒体
Java水解18 小时前
Nginx平滑升级与location配置案例详解
后端·nginx
00后程序员张19 小时前
Swoole HTTPS 实战,在生产环境部署、性能权衡与排查流程
后端·ios·小程序·https·uni-app·iphone·swoole
AirDroid_cn21 小时前
Win11 远程桌面:连接公司电脑时,提示 “证书错误” 如何解决?
windows·网络协议·https·ssl·电脑技巧
2501_915909061 天前
iOS App 上架全流程详解:证书配置、打包上传、审核技巧与跨平台上架工具 开心上架 实践
android·ios·小程序·https·uni-app·iphone·webview
2501_915918411 天前
开发 iOS 应用全流程指南,环境搭建、证书配置与跨平台使用 开心上架 上架AppStore
android·ios·小程序·https·uni-app·iphone·webview
心灵宝贝1 天前
nginx-1.16.1-2.p01.ky10.sw_64.rpm 安装教程(详细步骤,适用于Kylin V10/SW64架构)
nginx·架构·kylin
用户31187945592181 天前
nginx-1.16.1-2.p01.ky10.sw_64.rpm 安装教程(详细步骤,适用于Kylin V10/申威SW64架构)
nginx
2501_915106321 天前
Comodo HTTPS 在工程中的部署与排查实战(证书链、兼容性与真机抓包策略)
网络协议·http·ios·小程序·https·uni-app·iphone