nginx配置ssl证书
2020-05-26 本文已影响0人
二营长家的张大炮
免费证书网上应该很多
我用的是腾讯云的一年的免费证书



腾讯云提供的操作步骤:
https://cloud.tencent.com/document/product/400/35244
我们把证书下载下来
是一个文件夹

由于我的项目是部署在nginx上面的所以我需要把你滚下目录下的文件上传到nginx根目录conf下面
然后配置nginx
server {
#SSL 访问端口号为 443
listen 443 ssl;
#填写绑定证书的域名
server_name www.domain.com;
#证书文件名称
ssl_certificate 1_www.domain.com_bundle.crt;
#私钥文件名称
ssl_certificate_key 2_www.domain.com.key;
ssl_session_timeout 5m;
#请按照以下协议配置
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
#网站主页路径。此路径仅供参考,具体请您按照实际目录操作。
root /var/www/www.domain.com;
index index.html index.htm;
}
}
然后重启nginx
你以为就这样结束了?
错。。
重启时报错:
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/l...
然后我去网上找了资料成功解决了:
1.找到nginx源码包目录(即你安装nginx时上传的安装包)
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
然后执行make(不是make install)
然后备份并覆盖原有的nginx
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
此时要确保nginx是停止状态
停止nginx运行:/usr/local/nginx/sbin/nginx -s stop
然后会提示你是否要覆盖安装

然后再去nginx目录下测试配置是否成功
./sbin/nginx -t

此时就大功告成啦