版本:nginx/1.15.0
1、在阿里云下载免费的正式
2、安装之后将证书压缩包解压 解压完成会有两个文件
- xxx.key:证书的私钥文件
- xxx.pem:证书文件,crt是pem文件的扩展名
3、阿里云的教程说是在nginx的目录下创建cert目录,但是我试了不行,所以放到和nginx.conf同目录下面。
4、修改配置文件nginx.conf
修改前
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
修改后
#HTTPS server
server {
listen 443 ssl;
server_name localhost;
ssl_certificate a.pem;
ssl_certificate_key b.key;
root html;
index index.html index.htm;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
5、修改完成之后,重启就可以了。
遇到问题:
1、nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:110 报错 缺少ngx_http_ssl_module模块
编译的时候没有编译对应的模块,/usr/local/nginx/sbin/nginx -v 通过命令查看版本号以及编译时的参数。
查看configure arguments:后边有没有值,如果有,就复制下来。
进入到安装包目录中, 我是/usr/java/nginx-1.15.0
cd /usr/java/nginx-1.15.0
./configure --原来有的模块(如果有的话) --with-http_ssl_module
make #编译 最好先关掉nginx
编译完成后 将编译好的nginx覆盖原来的nginx (原来的nginx可以先备份)
cp ./objs/nginx /usr/local/nginx/sbin/
然后重启即可
nginx -t -c /usr/local/nginx/conf/nginx.conf #测试配置文件
nginx -c /usr/local/nginx/conf/nginx.conf
2、 [emerg] BIO_new_file("/usr/local/nginx/conf/cert/214291778530222.pem") faile
证书地址错误,不管绝对路径 、nginx下创建cert目录 好像都不行 最后放在和nginx.conf同个目录下
3、nginx: [warn] the "ssl" directive is deprecated, use the "listen ... ssl" directive instead in /usr/local/nginx/conf/nginx.conf:136
貌似是nginx不建议使用这个命令 直接使用以下替代。
listen 443 ssl;