配置HTTPS协议

什么是https?
“ HTTP over SSL/TLS ”意思就是带“安全套接层”的 http 协议,也可以理解为“带安全套的 http ”,所以会比较安全! 其中 SSL 是“ Secure Sockets Layer ” 的缩写,是“安全套接层”的意思。 TLS 是 “Transport Layer Security” 的缩写,是 ” 传输层安全协议 ” 的意思。 SSL 和 TLS 是同一个东西的不同阶段,理解为同一个东西也行,都是安全协议就对了。 
 

为什么要部署https?

因为相当于http使用明文传输,传输的内容容易被偷看和篡改,https更安全,一个企业级的网站,https是必须要的!

如何配置?

方式一

springboot配置,只需要通过server.ssl.*的参数完成配置即可,如下:

application.properties 配置文件参考配置:

server.port=8443
server.ssl.protocol=TLS
server.ssl.key-store=classpath:javastack.keystore
server.ssl.key-store-password=javastack
server.ssl.key-store-type=JKS

更多SSL参数如下:

server.ssl.ciphers= # Supported SSL ciphers.
server.ssl.client-auth= # Whether client authentication is wanted ("want") or needed ("need"). Requires a trust store.
server.ssl.enabled= # Enable SSL support.
server.ssl.enabled-protocols= # Enabled SSL protocols.
server.ssl.key-alias= # Alias that identifies the key in the key store.
server.ssl.key-password= # Password used to access the key in the key store.
server.ssl.key-store= # Path to the key store that holds the SSL certificate (typically a jks file).
server.ssl.key-store-password= # Password used to access the key store.
server.ssl.key-store-provider= # Provider for the key store.
server.ssl.key-store-type= # Type of the key store.
server.ssl.protocol=TLS # SSL protocol to use.
server.ssl.trust-store= # Trust store that holds SSL certificates.
server.ssl.trust-store-password= # Password used to access the trust store.
server.ssl.trust-store-provider= # Provider for the trust store.
server.ssl.trust-store-type= # Type of the trust store.

参数对应的类:org.springframework.boot.web.server.Ssl

 

方式二

1.获取certbot客户端

wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto

2.停止nginx

service nginx stop

3.生成证书(如果后期生成报错,先删除原有certbot-auto,按第一步重新下载certbot即可)

#使用-d追加多个域名
./certbot-auto certonly --standalone --email dgt@dgtlinux.xin --agree-tos -d dgtlinux.xin -d www.dgtlinux.xin
在证书生成之后,我们会在 “/etc/letsencrypt/live/dgtlinux.xin/” 域名目录下有4个文件就是生成的密钥证书文件。

cert.pem  - Apache服务器端证书
chain.pem  - Apache根证书和中继证书
fullchain.pem  - Nginx所需要ssl_certificate文件
privkey.pem - 安全证书KEY文件 

4.查看生成的证书

ls /etc/letsencrypt/live/dgtlinux.xin/

5.在nginx中配置证书

 ssl on;
 ssl_certificate      /etc/letsencrypt/live/dgtlinux.xin/fullchain.pem; 
 ssl_certificate_key  /etc/letsencrypt/live/dgtlinux.xin/privkey.pem; 
 ssl_session_timeout 5m;
 ssl_protocols TLSv1;
 ssl_ciphers HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM;
 ssl_prefer_server_ciphers on;

apache中配置证书

vim /etc/httpd/conf/httpd.conf
SSLCertificateFile /etc/letsencrypt/live/dgtlinux.xin/cert.pem; 
SSLCertificateKeyFile /etc/letsencrypt/live/dgtlinux.xin/chain.pem; 

6.启动nginx

service nginx start

编写更新脚本renew-cert.sh

#!/bin/bash
# 停止nginx
service nginx stop

# 续签
# --force-renew 强制更新
/root/certbot-auto renew --force-renew

# 启动nginx
service nginx start

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值