版本: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;