这个错误提示表明在Nginx配置文件(通常是nginx.conf)中使用了SSL(Secure Sockets Layer)相关的配置,但是Nginx没有加载相应的SSL模块。
/usr/local/nginx/sbin/nginx -V 2>&1 | grep --color=auto ssl
/usr/local/nginx/sbin/nginx:安装nginx的绝对路径
输出以下结果 则为安装已加载SSL模块:
configure arguments: --with-openssl=/XXX/openssl-1.1.1l --with-http_ssl_module
/XXX/openssl-1.1.1l:openssl安装位置
有这个就是安装了--with-http_ssl_module
1.打开Nginx配置文件(通常是nginx.conf)。
2.确保在配置文件中的server块中有正确的SSL配置,如listen 443 ssl;和证书路径等,这个在证书配置的官网有具体的所需配置。
3.nginx.conf配置举例:
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; map $http_upgrade $connection_upgrade { default upgrade; '' close; } sendfile on; keepalive_timeout 65; server { #HTTPS的默认访问端口443。 listen 443 ssl; #填写证书绑定的域名 server_name XXX; #填写证书文件名称 ssl_certificate cert/XXX.pem; #填写证书私钥文件名称 ssl_certificate_key cert/XXX.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; #自定义设置使用的TLS协议的类型以及加密套件(以下为配置示例,请您自行评估是否需要配置) #TLS协议版本越高,HTTPS通信的安全性越高,但是相较于低版本TLS协议,高版本TLS协议对浏览器的兼容性较差。 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; #表示优先使用服务端加密套件。默认开启 ssl_prefer_server_ciphers on; location / { root html/XXX; index index.html index.htm; try_files $uri $uri/ /index.html; } location /prod-api/{ proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://XXX:XXX/; } location /prod-system/{ proxy_pass http://XXX:XXX/; #修改为需要被反向代理的WebSocket的IP和端口号 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; } }
4.重新验证Nginx配置:
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
如果没有语法错误,启动Nginx
# 进入您希望存放 OpenSSL 源代码的目录 cd /XXX # 下载 OpenSSL 源代码,浏览器也能访问 https://www.openssl.org/source/openssl-1.1.1l.tar.gz # 解压 OpenSSL 源代码 tar -zxvf openssl-x.x.x.tar.gz make make install
如果出现报错:
Operating system: x86_64-whatever-linux2 You need Perl 5.
访问:https://www.cpan.org/src/5.0/离线下载也可以
wget https://www.cpan.org/src/5.0/perl-5.30.1.tar.gz tar -xzf perl-5.30.1.tar.gz cd perl-5.30.1 ./Configure -des -Dprefix=$HOME/localperl make make test make install
./configure --with-openssl=/usr/local/openssl --with-http_ssl_module make make install
验证配置
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
启动:/usr/local/nginx/sbin目录执行./nginx
重新加载配置:/usr/local/nginx/sbin目录执行./nginx -s reload